home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / vir_real / veos / part06 < prev    next >
Encoding:
Internet Message Format  |  1993-06-20  |  83.0 KB

  1. Path: wupost!uunet!decwrl!vixie!vixie!not-for-mail
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Newsgroups: comp.sources.unix
  4. Subject: v26i189: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part06/16
  5. Date: 25 Apr 1993 23:15:05 -0700
  6. Organization: Vixie Home Computing
  7. Lines: 3033
  8. Sender: vixie@vix.com
  9. Approved: paul@vix.com
  10. Message-ID: <1rful9$5nj@efficacy.home.vix.com>
  11. NNTP-Posting-Host: efficacy.home.vix.com
  12.  
  13. Submitted-By: voodoo@hitl.washington.edu (Geoffery Coco)
  14. Posting-Number: Volume 26, Issue 189
  15. Archive-Name: veos-2.0/part06
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 6 (of 16)."
  24. # Contents:  src/utils/xv_utils.c src/xlisp/xcore/c/unixstuff.c
  25. #   src/xlisp/xcore/c/xlfio.c src/xlisp/xcore/c/xlisp.h
  26. #   src/xlisp/xcore/c/xlmath.c src/xlisp/xcore/c/xlstruct.c
  27. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:37 1993
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'src/utils/xv_utils.c' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'src/utils/xv_utils.c'\"
  31. else
  32. echo shar: Extracting \"'src/utils/xv_utils.c'\" \(13040 characters\)
  33. sed "s/^X//" >'src/utils/xv_utils.c' <<'END_OF_FILE'
  34. X/****************************************************************************************
  35. X *                                            *
  36. X * file: xv_utils.c                                    *
  37. X *                                            *
  38. X * Sundry lisp utils for the veos project                        *
  39. X *                                            *
  40. X * creation: March 28, 1991                                *
  41. X *                                            *
  42. X *                                            *
  43. X * Includes utilities by:                                *
  44. X *                                            *
  45. X *    Geoff Coco                                    *
  46. X *    Dav Lion                                    *
  47. X *    Andy McDonald                                    *
  48. X *    Fran Taylor                                    *
  49. X *                                            *
  50. X ****************************************************************************************/
  51. X
  52. X/****************************************************************************************
  53. X * Copyright (C) 1992  Human Interface Technology Lab, Seattle                *
  54. X ****************************************************************************************/
  55. X
  56. X#include "xlisp.h"
  57. X#include "world.h"
  58. X#include <math.h>
  59. X#include <sys/time.h>
  60. X
  61. Xextern LVAL    true;
  62. X
  63. Xtypedef float     TMatrix[4][4];
  64. Xtypedef float     TTriple[3];
  65. Xtypedef float     TVector[4];
  66. X
  67. XLVAL ReverseList();
  68. Xboolean IsTripleElt();
  69. X
  70. X
  71. X/****************************************************************************************/
  72. XLVAL read_time ()
  73. X{
  74. X  struct timeval t;
  75. X  double          now, diff;
  76. X  static double then = 0.0;
  77. X  int            err;
  78. X
  79. X  err = gettimeofday( &t, 0);
  80. X/*
  81. X  fprintf( stderr, "%d %d\n", t.tv_sec, t.tv_usec);
  82. X*/
  83. X  if( err == -1)
  84. X    xlerror( "read-time: timer barfed");
  85. X  else
  86. X    {
  87. X      now = (double)t.tv_sec + (double)t.tv_usec / 1000000.0;
  88. X/*
  89. X      fprintf( stderr, "%f %f\n", now, then);
  90. X*/
  91. X      diff = now - then;
  92. X      then = now;
  93. X    }
  94. X  return cvflonum( diff);
  95. X}
  96. X/****************************************************************************************/
  97. X
  98. X
  99. X
  100. X/****************************************************************************************
  101. X *.native_sprintf -- data conversion.                            *
  102. X ****************************************************************************************/
  103. X
  104. XLVAL native_sprintf()
  105. X{
  106. X    str255    sLocal;
  107. X
  108. X    util_sprintf(sLocal);
  109. X
  110. X    return(cvstring(sLocal));
  111. X
  112. X    } /* native_sprintf */
  113. X/****************************************************************************************/
  114. X
  115. X
  116. X/****************************************************************************************
  117. X *.native_printf -- data conversion.                            *
  118. X ****************************************************************************************/
  119. X
  120. XLVAL native_printf()
  121. X{
  122. X    str255    sLocal;
  123. X
  124. X    util_sprintf(sLocal);
  125. X    fprintf(stderr, "%s\n", sLocal);
  126. X
  127. X    return(true);
  128. X
  129. X    } /* native_printf */
  130. X/****************************************************************************************/
  131. X
  132. X
  133. X
  134. X/****************************************************************************************
  135. X *.native_printf1 -- data conversion.                            *
  136. X ****************************************************************************************/
  137. X
  138. XLVAL native_printf1()
  139. X{
  140. X    str255    sLocal;
  141. X
  142. X    util_sprintf(sLocal);
  143. X    fprintf(stderr, "%s", sLocal);
  144. X
  145. X    return(true);
  146. X
  147. X    } /* native_printf1 */
  148. X/****************************************************************************************/
  149. X
  150. X
  151. X/****************************************************************************************/
  152. XTVeosErr util_sprintf(sDest)
  153. X    char    *sDest;
  154. X{
  155. X    LVAL    pXElt;
  156. X    str63    sZoot;
  157. X
  158. X    sDest[0] = '\0';
  159. X
  160. X    while (moreargs()) {
  161. X
  162. X    pXElt = xlgetarg();
  163. X
  164. X    if (!null(pXElt)) {
  165. X
  166. X        switch (ntype(pXElt)) {
  167. X
  168. X        case FIXNUM:
  169. X        sprintf(sZoot, "%d", getfixnum(pXElt));
  170. X        strcat(sDest, sZoot);
  171. X        break;
  172. X        
  173. X        case FLONUM:
  174. X        sprintf(sZoot, "%.2f", getflonum(pXElt));
  175. X        strcat(sDest, sZoot);
  176. X        break;
  177. X        
  178. X        case STRING:
  179. X        strcat(sDest, (char *) getstring(pXElt));
  180. X        break;
  181. X
  182. X        default:
  183. X        break;
  184. X        }
  185. X        }
  186. X    }
  187. X
  188. X    return(VEOS_SUCCESS);
  189. X
  190. X    } /* util_sprintf */
  191. X/****************************************************************************************/
  192. X
  193. X
  194. X
  195. X
  196. X/****************************************************************************************
  197. X *.native_sscanf -- data conversion.                            *
  198. X ****************************************************************************************/
  199. X
  200. XLVAL native_sscanf()
  201. X{
  202. X    LVAL    pData;
  203. X    LVAL    pList, pXElt;
  204. X    char    *pDataFinger;
  205. X
  206. X    xlsave1(pList);
  207. X    xlsave1(pXElt);
  208. X
  209. X    pData = xlgastring();
  210. X    xllastarg();
  211. X
  212. X    pDataFinger = (char *) getstring(pData);
  213. X    while (pDataFinger) {
  214. X
  215. X    /** skip white space **/
  216. X
  217. X    while (pDataFinger[0] == ' ')
  218. X        pDataFinger ++;
  219. X
  220. X    if (pDataFinger[0] == '\0')
  221. X        break;
  222. X
  223. X    /** StrToXElt() looks for ' ' or '\0' as delimiter **/
  224. X
  225. X    StrToXElt(pDataFinger, &pXElt);
  226. X    pList = cons(pXElt, pList);
  227. X
  228. X    pDataFinger = strchr(pDataFinger, ' ');
  229. X    }
  230. X
  231. X    pList = ReverseList(pList);
  232. X    
  233. X    xlpopn(2);
  234. X
  235. X    return(pList);
  236. X
  237. X    } /* native_sscanf */
  238. X/****************************************************************************************/
  239. X
  240. X
  241. X
  242. X
  243. X/****************************************************************************************/
  244. XTVeosErr XVUtils_LoadPrims()
  245. X{
  246. X    Xform_LoadPrims();
  247. X
  248. X#define UTIL_LOAD
  249. X#include "xv_utils.h"
  250. X#undef UTIL_LOAD
  251. X
  252. X    }
  253. X/****************************************************************************************/
  254. X
  255. X
  256. X
  257. X
  258. X/****************************************************************************************
  259. X * StrToXElt                                         */
  260. X
  261. XTVeosErr StrToXElt(sData, hXElt)
  262. X    char        *sData;
  263. X    LVAL        *hXElt;
  264. X{
  265. X    TVeosErr         iErr;
  266. X    char        *pFinger, cSave;
  267. X    int            iDots, iChars, iDigits;
  268. X    int            iType;
  269. X    LVAL        pXElt;
  270. X    float        fVal;
  271. X    int            iVal;
  272. X
  273. X    iErr = VEOS_SUCCESS;
  274. X    iType = FREE;
  275. X    iDigits = iDots = iChars = 0;
  276. X
  277. X    xlsave1(pXElt);
  278. X
  279. X    pFinger = sData;
  280. X
  281. X    /** minus not necessarily a character **/
  282. X
  283. X    if (pFinger[0] == '-')
  284. X    pFinger ++;
  285. X
  286. X
  287. X    while (TRUE) {
  288. X
  289. X    if (pFinger[0] == ' ' || pFinger[0] == '\0') {
  290. X        break;
  291. X        }
  292. X
  293. X    if (isdigit(pFinger[0]))
  294. X        iDigits ++;
  295. X    else if (pFinger[0] == '.')
  296. X        iDots ++;
  297. X    else 
  298. X        iChars ++;
  299. X    
  300. X    pFinger ++;
  301. X    }
  302. X
  303. X    cSave = pFinger[0];
  304. X    pFinger[0] = '\0';
  305. X
  306. X    if (iChars > 0 || iDots > 1)
  307. X    pXElt = cvstring(sData);
  308. X
  309. X    else {
  310. X    if (iDots == 0) {
  311. X        sscanf(sData, "%d", &iVal);
  312. X        pXElt = cvfixnum(iVal);
  313. X        }
  314. X    else {
  315. X        sscanf(sData, "%f", &fVal);
  316. X        pXElt = cvflonum(fVal);
  317. X        }
  318. X    }
  319. X
  320. X    pFinger[0] = cSave;
  321. X
  322. X    *hXElt = pXElt;
  323. X
  324. X    xlpop();
  325. X
  326. X    return(iErr);
  327. X
  328. X    } /* StrToXElt */
  329. X/****************************************************************************************/
  330. X
  331. X
  332. X
  333. X/****************************************************************************************/
  334. XLVAL ReverseList(pList)
  335. X    LVAL    pList;
  336. X{
  337. X    LVAL    pSave, pXElt; 
  338. X    
  339. X    xlsave1(pSave); 
  340. X    xlsave1(pXElt); 
  341. X
  342. X    while (!null(pList)) { 
  343. X    pSave = cdr(pList); 
  344. X    rplacd(pList, pXElt); 
  345. X    pXElt = pList; 
  346. X    pList = pSave; 
  347. X    } 
  348. X
  349. X    xlpopn(2); 
  350. X
  351. X    return(pXElt);
  352. X    
  353. X    } /* Native_ReverseList */
  354. X/****************************************************************************************/
  355. X
  356. X
  357. X
  358. X/****************************************************************************************/
  359. Xboolean    IsQuatElt(pXElt)
  360. X    LVAL    pXElt;
  361. X{
  362. X    return(vectorp(pXElt) &&
  363. X       getsz(pXElt) == 2 &&
  364. X       floatp(getelement(pXElt, 0)) &&
  365. X       IsTripleElt(getelement(pXElt, 1)));
  366. X
  367. X    } /* IsQuatElt */
  368. X/****************************************************************************************/
  369. X
  370. X
  371. X/****************************************************************************************/
  372. Xboolean    IsMatrixElt(pXElt)
  373. X    LVAL    pXElt;
  374. X{
  375. X    return(vectorp(pXElt) && getsz(pXElt) == 16);
  376. X
  377. X    } /* IsMatrixElt */
  378. X/****************************************************************************************/
  379. X
  380. X
  381. X/****************************************************************************************/
  382. Xvoid XVect2Mat(pXElt, pMat)
  383. X    LVAL    pXElt;
  384. X    TMatrix    pMat;
  385. X{
  386. X    int        iEltIndex;
  387. X
  388. X    /** assume sanity is checked **/
  389. X    for (iEltIndex = 0; iEltIndex < 16; iEltIndex ++)
  390. X    pMat[iEltIndex / 4][iEltIndex % 4] = getflonum(getelement(pXElt, iEltIndex));
  391. X
  392. X    } /* XVect2Mat */
  393. X/****************************************************************************************/
  394. X
  395. X
  396. X/****************************************************************************************/
  397. XLVAL Mat2XVect(pMat)
  398. X    TMatrix    pMat;
  399. X{
  400. X    LVAL    pXElt;
  401. X    int        iEltIndex;
  402. X
  403. X    xlsave1(pXElt);
  404. X
  405. X    /** assume sanity is checked **/
  406. X    pXElt = newvector(16);
  407. X
  408. X    for (iEltIndex = 0; iEltIndex < 16; iEltIndex ++)
  409. X    setelement(pXElt, iEltIndex, cvflonum(pMat[iEltIndex / 4][iEltIndex % 4]));
  410. X
  411. X    xlpop();
  412. X
  413. X    return(pXElt);
  414. X
  415. X    } /* Mat2XVect */
  416. X/****************************************************************************************/
  417. X
  418. X
  419. X/****************************************************************************************/
  420. Xboolean    IsTripleElt(pXElt)
  421. X    LVAL    pXElt;
  422. X{
  423. X    return(vectorp(pXElt) && getsz(pXElt) == 3);
  424. X
  425. X    } /* IsTripleElt */
  426. X/****************************************************************************************/
  427. X
  428. X
  429. X/****************************************************************************************/
  430. Xvoid XVect2Tri(pXElt, pTri)
  431. X    LVAL    pXElt;
  432. X    TTriple    pTri;
  433. X{
  434. X    /** assume sanity is checked **/
  435. X
  436. X    pTri[0] = getflonum(getelement(pXElt, 0));
  437. X    pTri[1] = getflonum(getelement(pXElt, 1));
  438. X    pTri[2] = getflonum(getelement(pXElt, 2));
  439. X
  440. X    } /* XVect2Tri */
  441. X/****************************************************************************************/
  442. X
  443. X
  444. X/****************************************************************************************/
  445. XLVAL Tri2XVect(pTri)
  446. X    TTriple    pTri;
  447. X{
  448. X    LVAL    pXElt;
  449. X
  450. X    xlsave1(pXElt);
  451. X
  452. X    /** assume sanity is checked **/
  453. X    pXElt = newvector(3);
  454. X
  455. X    setelement(pXElt, 0, cvflonum(pTri[0]));
  456. X    setelement(pXElt, 1, cvflonum(pTri[1]));
  457. X    setelement(pXElt, 2, cvflonum(pTri[2]));
  458. X
  459. X    xlpop();
  460. X
  461. X    return(pXElt);
  462. X
  463. X    } /* Tri2XVect */
  464. X/****************************************************************************************/
  465. X
  466. X
  467. X/****************************************************************************************/
  468. Xvoid XVect2Quat(pXElt, pVect)
  469. X    LVAL    pXElt;
  470. X    TVector    pVect;
  471. X{
  472. X    LVAL    pTri;
  473. X
  474. X    /** assume sanity is checked **/
  475. X
  476. X    pVect[0] = getflonum(getelement(pXElt, 0));
  477. X
  478. X    pTri = getelement(pXElt, 1);
  479. X    pVect[1] = getflonum(getelement(pTri, 0));
  480. X    pVect[2] = getflonum(getelement(pTri, 1));
  481. X    pVect[3] = getflonum(getelement(pTri, 2));
  482. X    
  483. X    } /* XVect2Quat */
  484. X/****************************************************************************************/
  485. X
  486. X
  487. X/****************************************************************************************/
  488. XLVAL Quat2XVect(pVect)
  489. X    TVector    pVect;
  490. X{
  491. X    LVAL    pXElt, pMid;
  492. X
  493. X    /** assume sanity is checked **/
  494. X
  495. X    xlsave1(pXElt);
  496. X    xlsave1(pMid);
  497. X
  498. X    pMid = newvector(3);
  499. X
  500. X    setelement(pMid, 0, cvflonum(pVect[1]));
  501. X    setelement(pMid, 1, cvflonum(pVect[2]));
  502. X    setelement(pMid, 2, cvflonum(pVect[3]));
  503. X
  504. X    pXElt = newvector(2);
  505. X           
  506. X    setelement(pXElt, 0, cvflonum(pVect[0]));
  507. X    setelement(pXElt, 1, pMid);
  508. X
  509. X    xlpopn(2);
  510. X
  511. X    return(pXElt);
  512. X
  513. X    } /* Quat2XVect */
  514. X/****************************************************************************************/
  515. X
  516. X
  517. X
  518. X/****************************************************************************************/
  519. Xvoid
  520. XLispMat2Mat(lMat, pMat)
  521. X    LVAL    lMat;
  522. X    float    pMat[4][4];
  523. X{    
  524. X    pMat[0][0] = getflonum(getelement(lMat, 0));
  525. X    pMat[0][1] = getflonum(getelement(lMat, 1));
  526. X    pMat[0][2] = getflonum(getelement(lMat, 2));
  527. X    pMat[0][3] = getflonum(getelement(lMat, 3));
  528. X
  529. X    pMat[1][0] = getflonum(getelement(lMat, 4));
  530. X    pMat[1][1] = getflonum(getelement(lMat, 5));
  531. X    pMat[1][2] = getflonum(getelement(lMat, 6));
  532. X    pMat[1][3] = getflonum(getelement(lMat, 7));
  533. X
  534. X    pMat[2][0] = getflonum(getelement(lMat, 8));
  535. X    pMat[2][1] = getflonum(getelement(lMat, 9));
  536. X    pMat[2][2] = getflonum(getelement(lMat, 10));
  537. X    pMat[2][3] = getflonum(getelement(lMat, 11));
  538. X
  539. X    pMat[3][0] = getflonum(getelement(lMat, 12));
  540. X    pMat[3][1] = getflonum(getelement(lMat, 13));
  541. X    pMat[3][2] = getflonum(getelement(lMat, 14));
  542. X    pMat[3][3] = getflonum(getelement(lMat, 15));
  543. X              
  544. X    
  545. X    }/*LispMat2Mat*/
  546. X/****************************************************************************************/
  547. X
  548. X
  549. X/****************************************************************************************/
  550. Xvoid
  551. XMat2LispMat(pMat, lMat)
  552. X     float    pMat[4][4];
  553. X     LVAL    lMat;
  554. X{
  555. X
  556. X    stuff_flonum(lMat, 0,     pMat[0][0]);
  557. X    stuff_flonum(lMat, 1,     pMat[0][1]);
  558. X    stuff_flonum(lMat, 2,     pMat[0][2]);
  559. X    stuff_flonum(lMat, 3,     pMat[0][3]);
  560. X    
  561. X    stuff_flonum(lMat, 4,     pMat[1][0]);
  562. X    stuff_flonum(lMat, 5,     pMat[1][1]);
  563. X    stuff_flonum(lMat, 6,     pMat[1][2]);
  564. X    stuff_flonum(lMat, 7,     pMat[1][3]);
  565. X    
  566. X    stuff_flonum(lMat, 8,     pMat[2][0]);
  567. X    stuff_flonum(lMat, 9,     pMat[2][1]);
  568. X    stuff_flonum(lMat, 10,     pMat[2][2]);
  569. X    stuff_flonum(lMat, 11,     pMat[2][3]);
  570. X    
  571. X    stuff_flonum(lMat, 12,     pMat[3][0]);
  572. X    stuff_flonum(lMat, 13,     pMat[3][1]);
  573. X    stuff_flonum(lMat, 14,     pMat[3][2]);
  574. X    stuff_flonum(lMat, 15,     pMat[3][3]);
  575. X
  576. X    }/*Mat2LispMat*/
  577. X/****************************************************************************************/
  578. X
  579. END_OF_FILE
  580. if test 13040 -ne `wc -c <'src/utils/xv_utils.c'`; then
  581.     echo shar: \"'src/utils/xv_utils.c'\" unpacked with wrong size!
  582. fi
  583. # end of 'src/utils/xv_utils.c'
  584. fi
  585. if test -f 'src/xlisp/xcore/c/unixstuff.c' -a "${1}" != "-c" ; then 
  586.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/unixstuff.c'\"
  587. else
  588. echo shar: Extracting \"'src/xlisp/xcore/c/unixstuff.c'\" \(14087 characters\)
  589. sed "s/^X//" >'src/xlisp/xcore/c/unixstuff.c' <<'END_OF_FILE'
  590. X/* -*-C-*-
  591. X********************************************************************************
  592. X*
  593. X* File:         unixstuff.c
  594. X* RCS:          $Header: unixstuff.c,v 1.3 89/11/25 05:12:16 mayer Exp $
  595. X* Description:  UNIX-Specific interfaces for XLISP
  596. X* Author:       David Michael Betz; Niels Mayer
  597. X* Created:      
  598. X* Modified:     Sat Nov 25 05:12:04 1989 (Niels Mayer) mayer@hplnpm
  599. X* Language:     C
  600. X* Package:      N/A
  601. X* Status:       X11r4 contrib tape release
  602. X*
  603. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  604. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  605. X*
  606. X* Permission to use, copy, modify, distribute, and sell this software and its
  607. X* documentation for any purpose is hereby granted without fee, provided that
  608. X* the above copyright notice appear in all copies and that both that
  609. X* copyright notice and this permission notice appear in supporting
  610. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  611. X* used in advertising or publicity pertaining to distribution of the software
  612. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  613. X* make no representations about the suitability of this software for any
  614. X* purpose. It is provided "as is" without express or implied warranty.
  615. X*
  616. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  617. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  618. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  619. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  620. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  621. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  622. X* PERFORMANCE OF THIS SOFTWARE.
  623. X*
  624. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  625. X* 
  626. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  627. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  628. X*
  629. X********************************************************************************
  630. X*/
  631. Xstatic char rcs_identity[] = "@(#)$Header: unixstuff.c,v 1.3 89/11/25 05:12:16 mayer Exp $";
  632. X
  633. X
  634. X#include "xlisp.h"
  635. X
  636. X/******************************************************************************
  637. X * Prim_POPEN - start a process and open a pipe for read/write 
  638. X * (code stolen from xlfio.c:xopen())
  639. X *
  640. X * syntax: (popen <command line> :direction <direction>)
  641. X *                <command line> is a string to be sent to the subshell (sh).
  642. X *                <direction> is either :input (to read from the pipe) or
  643. X *                                      :output (to write to the pipe).
  644. X *                                      (:input is the default)
  645. X *
  646. X * Popen returns a stream, or NIL if files or processes couldn't be created.
  647. X * The  success  of  the  command  execution  can be checked by examining the 
  648. X * return value of pclose. 
  649. X *
  650. X * Added to XLISP by Niels Mayer
  651. X ******************************************************************************/
  652. XLVAL Prim_POPEN()
  653. X{
  654. X  extern LVAL k_direction, k_input, k_output;
  655. X  char *name,*mode;
  656. X  FILE *fp;
  657. X  LVAL dir;
  658. X
  659. X  /* get the process name and direction */
  660. X  name = (char *) getstring(xlgastring());
  661. X  if (!xlgetkeyarg(k_direction, &dir))
  662. X    dir = k_input;
  663. X  
  664. X  /* get the mode */
  665. X  if (dir == k_input)
  666. X    mode = "r";
  667. X  else if (dir == k_output)
  668. X    mode = "w";
  669. X  else
  670. X    xlerror("bad direction",dir);
  671. X  
  672. X  /* try to open the file */
  673. X  return ((fp = popen(name,mode)) ? cvfile(fp) : NIL);
  674. X}
  675. X
  676. X
  677. X/******************************************************************************
  678. X * Prim_PCLOSE - close a pipe opened by Prim_POPEN().
  679. X * (code stolen from xlfio.c:xclose())
  680. X *
  681. X * syntax: (pclose <stream>)
  682. X *                  <stream> is a stream created by popen.
  683. X * returns T if the command executed successfully, otherwise, 
  684. X * returns the exit status of the opened command.
  685. X *
  686. X * Added to XLISP by Niels Mayer
  687. X ******************************************************************************/
  688. XLVAL Prim_PCLOSE()
  689. X{
  690. X  extern LVAL true;
  691. X  LVAL fptr;
  692. X  int  result;
  693. X
  694. X  /* get file pointer */
  695. X  fptr = xlgastream();
  696. X  xllastarg();
  697. X
  698. X  /* make sure the file exists */
  699. X  if (getfile(fptr) == NULL)
  700. X    xlfail("file not open");
  701. X
  702. X  /* close the pipe */
  703. X  result = pclose(getfile(fptr));
  704. X
  705. X  if (result == -1)
  706. X    xlfail("<stream> has not been opened with popen");
  707. X    
  708. X  setfile(fptr,NULL);
  709. X
  710. X  /* return T if success (exit status 0), else return exit status */
  711. X  return (result ? cvfixnum(result) : true);
  712. X}
  713. X
  714. X
  715. X/******************************************************************************
  716. X * Prim_SYSTEM - run a process, sending output (if any) to stdout/stderr
  717. X *
  718. X * syntax: (system <command line>)
  719. X *                 <command line> is a string to be sent to the subshell (sh).
  720. X *
  721. X * Returns T if the command executed succesfully, otherwise returns the 
  722. X * integer shell exit status for the command.
  723. X *
  724. X * Added to XLISP by Niels Mayer
  725. X ******************************************************************************/
  726. XLVAL Prim_SYSTEM()
  727. X{
  728. X  extern LVAL true;
  729. X  extern int sys_nerr;
  730. X  extern char *sys_errlist[];
  731. X  extern int errno;
  732. X  LVAL command;
  733. X  int  result;
  734. X  char temptext[1024];
  735. X
  736. X  /* get shell command */
  737. X  command = xlgastring();
  738. X  xllastarg();
  739. X  
  740. X  /* run the process */
  741. X  result = system((char *) getstring(command));
  742. X
  743. X  if (result == -1) {        /* if a system error has occured */
  744. X    if (errno < sys_nerr)
  745. X      (void) sprintf(temptext, "Error in system(3S): %s\n", sys_errlist[errno]);
  746. X    else
  747. X      (void) strcpy(temptext, "Error in system(3S): unknown error\n");
  748. X    xlfail(temptext);
  749. X  }
  750. X
  751. X  /* return T if success (exit status 0), else return exit status */
  752. X  return (result ? cvfixnum(result) : true);
  753. X}
  754. X
  755. X
  756. X/******************************************************************************
  757. X * (FSCANF-FIXNUM <stream> <scanf-format>)
  758. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  759. X * via open or popen. It will not work on an USTREAM.
  760. X * <scanf-format> is a format string containing a single conversion
  761. X * directive that will result in an integer valued conversion.
  762. X * %d, %u, %o, %x, %ld, %lu, %lo and %lx style conversions 
  763. X * are acceptable for this routine.
  764. X * WARNING: specifying a <scanf-format> that will result in the conversion
  765. X * of a result larger than sizeof(long) will result in corrupted memory and
  766. X * core dumps. 
  767. X * 
  768. X * This routine will return an FIXNUM if fscanf() returns 1 (i.e. if
  769. X * the one expected conversion has succeeded. It will return NIL if the
  770. X * conversion wasn't successful, or if EOF was reached.
  771. X ******************************************************************************/
  772. XLVAL Prim_FSCANF_FIXNUM()
  773. X{
  774. X  LVAL  lval_stream;
  775. X  char* fmt;
  776. X  long  result;
  777. X  
  778. X  lval_stream = xlgastream();
  779. X  if (getfile(lval_stream) == NULL)
  780. X    xlerror("File not opened.", lval_stream);
  781. X  fmt = (char *) getstring(xlgastring());
  782. X  xllastarg();
  783. X  
  784. X  result = 0L;            /* clear it out hibits incase short is written */
  785. X  /* if scanf returns result <1 then an error or eof occured. */
  786. X  if (fscanf(getfile(lval_stream), fmt, &result) < 1)
  787. X    return (NIL);
  788. X  else
  789. X    return (cvfixnum((FIXTYPE) result));
  790. X}
  791. X
  792. X
  793. X/******************************************************************************
  794. X * (FSCANF-STRING <stream> <scanf-format>)
  795. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  796. X * via open or popen. It will not work on an USTREAM.
  797. X * <scanf-format> is a format string containing a single conversion
  798. X * directive that will result in a string valued conversion.
  799. X * %s, %c, and %[...] style conversions are acceptable for
  800. X * this routine.
  801. X * WARNING: specifying a <scanf-format> that will result in the conversion
  802. X * of a result larger than 1024 characters will result in corrupted
  803. X * memory and core dumps.
  804. X * 
  805. X * This routine will return a string if fscanf() returns 1 (i.e. if
  806. X * the one expected conversion has succeeded. It will return NIL if the
  807. X * conversion wasn't successful, or if EOF was reached.
  808. X ******************************************************************************/
  809. XLVAL Prim_FSCANF_STRING()
  810. X{
  811. X  LVAL lval_stream;
  812. X  char* fmt;
  813. X  char result[BUFSIZ];
  814. X
  815. X  
  816. X  lval_stream = xlgastream();
  817. X  if (getfile(lval_stream) == NULL)
  818. X    xlerror("File not opened.", lval_stream);
  819. X  fmt = (char *) getstring(xlgastring());
  820. X  xllastarg();
  821. X  
  822. X  result[0] = result[1] = '\0';    /* if the conversion is %c, then fscanf
  823. X                   doesn't null terminate the string,
  824. X                   so do it just incase */
  825. X
  826. X  /* if scanf returns result <1 then an error or eof occured. */
  827. X  if (fscanf(getfile(lval_stream), fmt, result) < 1)
  828. X    return (NIL);
  829. X  else
  830. X    return (cvstring(result));
  831. X}
  832. X
  833. X
  834. X/******************************************************************************
  835. X * (FSCANF-FLONUM <stream> <scanf-format>)
  836. X * This routine calls fscanf(3s) on a <stream> that was previously openend
  837. X * via open or popen. It will not work on an USTREAM.
  838. X * <scanf-format> is a format string containing a single conversion
  839. X * directive that will result in an FLONUM valued conversion.
  840. X * %e %f or %g are valid conversion specifiers for this routine.
  841. X *
  842. X * WARNING: specifying a <scanf-format> that will result in the conversion
  843. X * of a result larger than sizeof(float) will result in corrupted memory and
  844. X * core dumps. 
  845. X * 
  846. X * This routine will return a FLONUM if fscanf() returns 1 (i.e. if
  847. X * the one expected conversion has succeeded. It will return NIL if the
  848. X * conversion wasn't successful, or if EOF was reached.
  849. X ******************************************************************************/
  850. XLVAL Prim_FSCANF_FLONUM()
  851. X{
  852. X  LVAL lval_stream;
  853. X  char* fmt;
  854. X  FILE * fp;
  855. X  float result;
  856. X  
  857. X  lval_stream = xlgastream();
  858. X  if (getfile(lval_stream) == NULL)
  859. X    xlerror("File not opened.", lval_stream);
  860. X  fmt = (char *) getstring(xlgastring());
  861. X  xllastarg();
  862. X  
  863. X  /* if scanf returns result <1 then an error or eof occured. */
  864. X  if (fscanf(getfile(lval_stream), fmt, &result) < 1)
  865. X    return (NIL);
  866. X  else
  867. X    return (cvflonum((FLOTYPE) result));
  868. X}
  869. X
  870. X
  871. X/******************************************************************************/
  872. X/******************************************************************************/
  873. X/******************************************************************************/
  874. X/* -- stuff.c  -- operating system specific routines */
  875. X/* -- Written by dbetz for XLISP 2.0 */
  876. X/* -- Copied by EFJohnson from a BIX message */
  877. X/* -- Unix System V */
  878. X
  879. X#define    LBSIZE    200
  880. X
  881. X/* -- external variables */
  882. Xextern    FILE    *tfp;
  883. X
  884. X/* -- local variables */
  885. Xstatic    long    rseed = 1L;
  886. X
  887. Xstatic    char    lbuf[LBSIZE];
  888. Xstatic    int    lindex;
  889. Xstatic    int    lcount;
  890. X
  891. X
  892. X/* -- osinit - initialize */
  893. Xosinit(banner)
  894. Xchar    *banner;
  895. X{
  896. X    printf("%s\n", banner );
  897. X    lindex    = 0;
  898. X    lcount    = 0;
  899. X}
  900. X
  901. X/* -- osfinish - clean up before returning to the operating system */
  902. Xosfinish()
  903. X{
  904. X}
  905. X
  906. X
  907. X/* -- xoserror - print an error message */
  908. Xxoserror(msg)
  909. X
  910. Xchar    *msg;
  911. X
  912. X{
  913. X    printf( "error: %s\n", msg );
  914. X}
  915. X
  916. X
  917. X/* -- osrand - return a random number between 0 and n-1 */
  918. Xint osrand(n)
  919. X
  920. Xint    n;
  921. X
  922. X{
  923. X    long k1;
  924. X
  925. X    /* -- make sure we don't get stuck at zero */
  926. X    if ( rseed == 0L ) rseed = 1L;
  927. X
  928. X    /* -- algorithm taken from Dr Dobbs Journal, Nov. 1985, page 91 */
  929. X    k1 = rseed / 127773L;
  930. X    if ( ( rseed = 16807L * (rseed - k1 * 127773L) -k1 * 2836L) < 0L )
  931. X        rseed += 2147483647L;
  932. X
  933. X    /* -- return a random number between 0 and n-1 */
  934. X    return( (int) (rseed % (long) n ) );
  935. X}
  936. X
  937. X
  938. X
  939. X/* -- osaopen -- open an ascii file */
  940. XFILE    *osaopen( name, mode )
  941. Xchar    *name, *mode;
  942. X{
  943. X    return( fopen( name, mode ) );
  944. X}
  945. X
  946. X
  947. X
  948. X/* -- osbopen -- open a binary file */
  949. XFILE    *osbopen( name, mode )
  950. Xchar    *name, *mode;
  951. X{
  952. X    return( fopen( name, mode ) );
  953. X}
  954. X
  955. X
  956. X/* -- osclose -- close a file */
  957. Xint    osclose( fp )
  958. XFILE    *fp;
  959. X{
  960. X    return( fclose( fp ) );
  961. X}
  962. X
  963. X
  964. X/* -- osagetc - get a character from an ASCII file */
  965. Xint    osagetc( fp )
  966. XFILE    *fp;
  967. X{
  968. X    return( getc(fp) );
  969. X}
  970. X
  971. X/* -- osaputc - put a character to an ASCII file */
  972. Xint    osaputc( ch, fp )
  973. Xint    ch;
  974. XFILE    *fp;
  975. X{
  976. X    return( putc( ch, fp ) );
  977. X}
  978. X
  979. X
  980. X
  981. X/* -- osbgetc - get a character from a binary file */
  982. Xint    osbgetc( fp )
  983. XFILE    *fp;
  984. X{
  985. X    return( getc(fp) );
  986. X}
  987. X
  988. X/* -- osbputc - put a character to a binary file */
  989. Xint    osbputc( ch, fp )
  990. Xint    ch;
  991. XFILE    *fp;
  992. X{
  993. X    return( putc( ch, fp ) );
  994. X}
  995. X
  996. X
  997. X/* -- ostgetc - get a character from the terminal */
  998. Xint    ostgetc()
  999. X{
  1000. X    while(--lcount < 0 )
  1001. X        {
  1002. X        if ( fgets(lbuf,LBSIZE,stdin) == NULL )
  1003. X            return( EOF );
  1004. X        if ( tfp )
  1005. X            fputs( lbuf, tfp );
  1006. X        lcount = strlen( lbuf );
  1007. X        lindex = 0;
  1008. X        }
  1009. X
  1010. X    return( lbuf[lindex++] );
  1011. X}
  1012. X
  1013. X
  1014. X/* -- ostputc - put a character to the terminal */
  1015. Xostputc( ch )
  1016. Xint    ch;
  1017. X{
  1018. X    /* -- check for control characters */
  1019. X    oscheck();
  1020. X    
  1021. X    /* -- output the character */
  1022. X    putchar( ch );
  1023. X
  1024. X    /* -- output the char to the transcript file */
  1025. X    if ( tfp )
  1026. X        osaputc( ch, tfp );
  1027. X}
  1028. X
  1029. X
  1030. X
  1031. X
  1032. X/* -- osflush - flush the terminal input buffer */
  1033. Xosflush()
  1034. X{
  1035. X    lindex = lcount = 0;
  1036. X}
  1037. X
  1038. X
  1039. X/* -- oscheck - check for control characters during execution */
  1040. Xoscheck()
  1041. X{
  1042. X}
  1043. X
  1044. X
  1045. X/* -- ossymbols - enter os-specific symbols */
  1046. Xossymbols()
  1047. X{
  1048. X}
  1049. X
  1050. X/******************************************************************************
  1051. X * xosgetenv - get string from environment
  1052. X * 
  1053. X * syntax: (getenv key)
  1054. X *                <key> is something like TERM to look up in the unix environment.
  1055. X * 
  1056. X * If "<key>=<val> is not found in the environment, xosgetenv returns NIL.
  1057. X * Otherwise, xosgetenv returns a list of strings, one for each ':'-delimited
  1058. X * component of <val>.
  1059. X *
  1060. X * Added to XLISP by Jeff Prothero
  1061. X ******************************************************************************/
  1062. XLVAL envget( key_as_asciz )
  1063. Xchar*        key_as_asciz;
  1064. X{
  1065. X    extern char* getenv();
  1066. X    LVAL result;
  1067. X    char *val_as_asciz = getenv( key_as_asciz );
  1068. X    xlsave1( result );
  1069. X    if (val_as_asciz != NULL) {
  1070. X    do {
  1071. X        char buf[ 1024 ];
  1072. X            char *dst = buf;
  1073. X        while (*val_as_asciz   &&   *val_as_asciz != ':') {
  1074. X        *dst++ = *val_as_asciz++;
  1075. X        }
  1076. X        *dst = '\0';
  1077. X        result = cons( cvstring(buf), result );
  1078. X    } while (*val_as_asciz++);
  1079. X    }
  1080. X    xlpop();
  1081. X    return result;
  1082. X}
  1083. XLVAL xosenvget()
  1084. X{
  1085. X    char *key_as_asciz = (char *) getstring(xlgastring());
  1086. X    xllastarg();
  1087. X    return envget( key_as_asciz );
  1088. X}
  1089. END_OF_FILE
  1090. if test 14087 -ne `wc -c <'src/xlisp/xcore/c/unixstuff.c'`; then
  1091.     echo shar: \"'src/xlisp/xcore/c/unixstuff.c'\" unpacked with wrong size!
  1092. fi
  1093. # end of 'src/xlisp/xcore/c/unixstuff.c'
  1094. fi
  1095. if test -f 'src/xlisp/xcore/c/xlfio.c' -a "${1}" != "-c" ; then 
  1096.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlfio.c'\"
  1097. else
  1098. echo shar: Extracting \"'src/xlisp/xcore/c/xlfio.c'\" \(11944 characters\)
  1099. sed "s/^X//" >'src/xlisp/xcore/c/xlfio.c' <<'END_OF_FILE'
  1100. X/* -*-C-*-
  1101. X********************************************************************************
  1102. X*
  1103. X* File:         xlfio.c
  1104. X* RCS:          $Header: xlfio.c,v 1.4 89/11/25 05:24:44 mayer Exp $
  1105. X* Description:  xlisp file i/o
  1106. X* Author:       David Michael Betz
  1107. X* Created:      
  1108. X* Modified:     Sat Nov 25 05:24:25 1989 (Niels Mayer) mayer@hplnpm
  1109. X* Language:     C
  1110. X* Package:      N/A
  1111. X* Status:       X11r4 contrib tape release
  1112. X*
  1113. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  1114. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  1115. X*
  1116. X* Permission to use, copy, modify, distribute, and sell this software and its
  1117. X* documentation for any purpose is hereby granted without fee, provided that
  1118. X* the above copyright notice appear in all copies and that both that
  1119. X* copyright notice and this permission notice appear in supporting
  1120. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  1121. X* used in advertising or publicity pertaining to distribution of the software
  1122. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  1123. X* make no representations about the suitability of this software for any
  1124. X* purpose. It is provided "as is" without express or implied warranty.
  1125. X*
  1126. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  1127. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1128. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  1129. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1130. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1131. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1132. X* PERFORMANCE OF THIS SOFTWARE.
  1133. X*
  1134. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  1135. X* 
  1136. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  1137. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  1138. X*
  1139. X********************************************************************************
  1140. X*/
  1141. Xstatic char rcs_identity[] = "@(#)$Header: xlfio.c,v 1.4 89/11/25 05:24:44 mayer Exp $";
  1142. X
  1143. X#include "xlisp.h"
  1144. X
  1145. X/* external variables */
  1146. Xextern LVAL k_direction,k_input,k_output;
  1147. Xextern LVAL s_stdin,s_stdout,s_stderr,true;
  1148. Xextern unsigned char buf[];
  1149. Xextern int xlfsize;
  1150. X
  1151. X/* external routines */
  1152. Xextern FILE *osaopen();
  1153. X
  1154. X/* forward declarations */
  1155. XFORWARD LVAL getstroutput();
  1156. XFORWARD LVAL printit();
  1157. XFORWARD LVAL flatsize();
  1158. XFORWARD LVAL openit();
  1159. X
  1160. X/* xread - read an expression */
  1161. XLVAL xread()
  1162. X{
  1163. X    LVAL fptr,eof,rflag,val;
  1164. X
  1165. X    /* get file pointer and eof value */
  1166. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1167. X    eof = (moreargs() ? xlgetarg() : NIL);
  1168. X    rflag = (moreargs() ? xlgetarg() : NIL);
  1169. X    xllastarg();
  1170. X
  1171. X    /* read an expression */
  1172. X    if (!xlread(fptr,&val,rflag != NIL))
  1173. X    val = eof;
  1174. X
  1175. X    /* return the expression */
  1176. X    return (val);
  1177. X}
  1178. X
  1179. X/* xprint - built-in function 'print' */
  1180. XLVAL xprint()
  1181. X{
  1182. X    return (printit(TRUE,TRUE));
  1183. X}
  1184. X
  1185. X/* xprin1 - built-in function 'prin1' */
  1186. XLVAL xprin1()
  1187. X{
  1188. X    return (printit(TRUE,FALSE));
  1189. X}
  1190. X
  1191. X/* xprinc - built-in function princ */
  1192. XLVAL xprinc()
  1193. X{
  1194. X    return (printit(FALSE,FALSE));
  1195. X}
  1196. X
  1197. X/* xterpri - terminate the current print line */
  1198. XLVAL xterpri()
  1199. X{
  1200. X    LVAL fptr;
  1201. X
  1202. X    /* get file pointer */
  1203. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1204. X    xllastarg();
  1205. X
  1206. X    /* terminate the print line and return nil */
  1207. X    xlterpri(fptr);
  1208. X    return (NIL);
  1209. X}
  1210. X
  1211. X/* printit - common print function */
  1212. XLOCAL LVAL printit(pflag,tflag)
  1213. X  int pflag,tflag;
  1214. X{
  1215. X    LVAL fptr,val;
  1216. X
  1217. X    /* get expression to print and file pointer */
  1218. X    val = xlgetarg();
  1219. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1220. X    xllastarg();
  1221. X
  1222. X    /* print the value */
  1223. X    xlprint(fptr,val,pflag);
  1224. X
  1225. X    /* terminate the print line if necessary */
  1226. X    if (tflag)
  1227. X    xlterpri(fptr);
  1228. X
  1229. X    /* return the result */
  1230. X    return (val);
  1231. X}
  1232. X
  1233. X/* xflatsize - compute the size of a printed representation using prin1 */
  1234. XLVAL xflatsize()
  1235. X{
  1236. X    return (flatsize(TRUE));
  1237. X}
  1238. X
  1239. X/* xflatc - compute the size of a printed representation using princ */
  1240. XLVAL xflatc()
  1241. X{
  1242. X    return (flatsize(FALSE));
  1243. X}
  1244. X
  1245. X/* flatsize - compute the size of a printed expression */
  1246. XLOCAL LVAL flatsize(pflag)
  1247. X  int pflag;
  1248. X{
  1249. X    LVAL val;
  1250. X
  1251. X    /* get the expression */
  1252. X    val = xlgetarg();
  1253. X    xllastarg();
  1254. X
  1255. X    /* print the value to compute its size */
  1256. X    xlfsize = 0;
  1257. X    xlprint(NIL,val,pflag);
  1258. X
  1259. X    /* return the length of the expression */
  1260. X    return (cvfixnum((FIXTYPE)xlfsize));
  1261. X}
  1262. X
  1263. X/* xopen - open a file */
  1264. XLVAL xopen()
  1265. X{
  1266. X    char *name,*mode;
  1267. X    FILE *fp;
  1268. X    LVAL dir;
  1269. X
  1270. X    /* get the file name and direction */
  1271. X    name = (char *)getstring(xlgetfname());
  1272. X    if (!xlgetkeyarg(k_direction,&dir))
  1273. X    dir = k_input;
  1274. X
  1275. X    /* get the mode */
  1276. X    if (dir == k_input)
  1277. X    mode = "r";
  1278. X    else if (dir == k_output)
  1279. X    mode = "w";
  1280. X    else
  1281. X    xlerror("bad direction",dir);
  1282. X
  1283. X    /* try to open the file */
  1284. X    return ((fp = osaopen(name,mode)) ? cvfile(fp) : NIL);
  1285. X}
  1286. X
  1287. X/* xclose - close a file */
  1288. XLVAL xclose()
  1289. X{
  1290. X    LVAL fptr;
  1291. X
  1292. X    /* get file pointer */
  1293. X    fptr = xlgastream();
  1294. X    xllastarg();
  1295. X
  1296. X    /* make sure the file exists */
  1297. X    if (getfile(fptr) == NULL)
  1298. X    xlfail("file not open");
  1299. X
  1300. X    /* close the file */
  1301. X    osclose(getfile(fptr));
  1302. X    setfile(fptr,NULL);
  1303. X
  1304. X    /* return nil */
  1305. X    return (NIL);
  1306. X}
  1307. X
  1308. X/* xrdchar - read a character from a file */
  1309. XLVAL xrdchar()
  1310. X{
  1311. X    LVAL fptr;
  1312. X    int ch;
  1313. X
  1314. X    /* get file pointer */
  1315. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1316. X    xllastarg();
  1317. X
  1318. X    /* get character and check for eof */
  1319. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvchar(ch));
  1320. X}
  1321. X
  1322. X/* xrdbyte - read a byte from a file */
  1323. XLVAL xrdbyte()
  1324. X{
  1325. X    LVAL fptr;
  1326. X    int ch;
  1327. X
  1328. X    /* get file pointer */
  1329. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1330. X    xllastarg();
  1331. X
  1332. X    /* get character and check for eof */
  1333. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvfixnum((FIXTYPE)ch));
  1334. X}
  1335. X
  1336. X/* xpkchar - peek at a character from a file */
  1337. XLVAL xpkchar()
  1338. X{
  1339. X    LVAL flag,fptr;
  1340. X    int ch;
  1341. X
  1342. X    /* peek flag and get file pointer */
  1343. X    flag = (moreargs() ? xlgetarg() : NIL);
  1344. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1345. X    xllastarg();
  1346. X
  1347. X    /* skip leading white space and get a character */
  1348. X    if (flag)
  1349. X    while ((ch = xlpeek(fptr)) != EOF && isspace(ch))
  1350. X        xlgetc(fptr);
  1351. X    else
  1352. X    ch = xlpeek(fptr);
  1353. X
  1354. X    /* return the character */
  1355. X    return (ch == EOF ? NIL : cvchar(ch));
  1356. X}
  1357. X
  1358. X/* xwrchar - write a character to a file */
  1359. XLVAL xwrchar()
  1360. X{
  1361. X    LVAL fptr,chr;
  1362. X
  1363. X    /* get the character and file pointer */
  1364. X    chr = xlgachar();
  1365. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1366. X    xllastarg();
  1367. X
  1368. X    /* put character to the file */
  1369. X    xlputc(fptr,getchcode(chr));
  1370. X
  1371. X    /* return the character */
  1372. X    return (chr);
  1373. X}
  1374. X
  1375. X/* xwrbyte - write a byte to a file */
  1376. XLVAL xwrbyte()
  1377. X{
  1378. X    LVAL fptr,chr;
  1379. X
  1380. X    /* get the byte and file pointer */
  1381. X    chr = xlgafixnum();
  1382. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  1383. X    xllastarg();
  1384. X
  1385. X    /* put byte to the file */
  1386. X    xlputc(fptr,(int)getfixnum(chr));
  1387. X
  1388. X    /* return the character */
  1389. X    return (chr);
  1390. X}
  1391. X
  1392. X/* xreadline - read a line from a file */
  1393. XLVAL xreadline()
  1394. X{
  1395. X    unsigned char buf[STRMAX+1],*p,*sptr;
  1396. X    LVAL fptr,str,newstr;
  1397. X    int len,blen,ch;
  1398. X
  1399. X    /* protect some pointers */
  1400. X    xlsave1(str);
  1401. X
  1402. X    /* get file pointer */
  1403. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  1404. X    xllastarg();
  1405. X
  1406. X    /* get character and check for eof */
  1407. X    len = blen = 0; p = buf;
  1408. X    while ((ch = xlgetc(fptr)) != EOF && ch != '\n') {
  1409. X
  1410. X    /* check for buffer overflow */
  1411. X    if (blen >= STRMAX) {
  1412. X         newstr = newstring(len + STRMAX + 1);
  1413. X        sptr = getstring(newstr); *sptr = '\0';
  1414. X        if (str) strcat(sptr,getstring(str));
  1415. X        *p = '\0'; strcat(sptr,buf);
  1416. X        p = buf; blen = 0;
  1417. X        len += STRMAX;
  1418. X        str = newstr;
  1419. X    }
  1420. X
  1421. X    /* store the character */
  1422. X    *p++ = ch; ++blen;
  1423. X    }
  1424. X
  1425. X    /* check for end of file */
  1426. X    if (len == 0 && p == buf && ch == EOF) {
  1427. X    xlpop();
  1428. X    return (NIL);
  1429. X    }
  1430. X
  1431. X    /* append the last substring */
  1432. X    if (str == NIL || blen) {
  1433. X    newstr = newstring(len + blen + 1);
  1434. X    sptr = getstring(newstr); *sptr = '\0';
  1435. X    if (str) strcat(sptr,getstring(str));
  1436. X    *p = '\0'; strcat(sptr,buf);
  1437. X    str = newstr;
  1438. X    }
  1439. X
  1440. X    /* restore the stack */
  1441. X    xlpop();
  1442. X
  1443. X    /* return the string */
  1444. X    return (str);
  1445. X}
  1446. X
  1447. X
  1448. X/* xmkstrinput - make a string input stream */
  1449. XLVAL xmkstrinput()
  1450. X{
  1451. X    int start,end,len,i;
  1452. X    unsigned char *str;
  1453. X    LVAL string,val;
  1454. X
  1455. X    /* protect the return value */
  1456. X    xlsave1(val);
  1457. X    
  1458. X    /* get the string and length */
  1459. X    string = xlgastring();
  1460. X    str = getstring(string);
  1461. X    len = getslength(string) - 1;
  1462. X
  1463. X    /* get the starting offset */
  1464. X    if (moreargs()) {
  1465. X    val = xlgafixnum();
  1466. X    start = (int)getfixnum(val);
  1467. X    }
  1468. X    else start = 0;
  1469. X
  1470. X    /* get the ending offset */
  1471. X    if (moreargs()) {
  1472. X    val = xlgafixnum();
  1473. X    end = (int)getfixnum(val);
  1474. X    }
  1475. X    else end = len;
  1476. X    xllastarg();
  1477. X
  1478. X    /* check the bounds */
  1479. X    if (start < 0 || start > len)
  1480. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)start));
  1481. X    if (end < 0 || end > len)
  1482. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)end));
  1483. X
  1484. X    /* make the stream */
  1485. X    val = newustream();
  1486. X
  1487. X    /* copy the substring into the stream */
  1488. X    for (i = start; i < end; ++i)
  1489. X    xlputc(val,str[i]);
  1490. X
  1491. X    /* restore the stack */
  1492. X    xlpop();
  1493. X
  1494. X    /* return the new stream */
  1495. X    return (val);
  1496. X}
  1497. X
  1498. X/* xmkstroutput - make a string output stream */
  1499. XLVAL xmkstroutput()
  1500. X{
  1501. X    return (newustream());
  1502. X}
  1503. X
  1504. X/* xgetstroutput - get output stream string */
  1505. XLVAL xgetstroutput()
  1506. X{
  1507. X    LVAL stream;
  1508. X    stream = xlgaustream();
  1509. X    xllastarg();
  1510. X    return (getstroutput(stream));
  1511. X}
  1512. X
  1513. X/* xgetlstoutput - get output stream list */
  1514. XLVAL xgetlstoutput()
  1515. X{
  1516. X    LVAL stream,val;
  1517. X
  1518. X    /* get the stream */
  1519. X    stream = xlgaustream();
  1520. X    xllastarg();
  1521. X
  1522. X    /* get the output character list */
  1523. X    val = gethead(stream);
  1524. X
  1525. X    /* empty the character list */
  1526. X    sethead(stream,NIL);
  1527. X    settail(stream,NIL);
  1528. X
  1529. X    /* return the list */
  1530. X    return (val);
  1531. X}
  1532. X
  1533. X/* xformat - formatted output function */
  1534. XLVAL xformat()
  1535. X{
  1536. X    LVAL fmtstring,stream,val;
  1537. X    unsigned char *fmt;
  1538. X    int ch;
  1539. X
  1540. X    /* protect some pointers */
  1541. X    xlstkcheck(2);
  1542. X    xlsave(fmtstring);
  1543. X    xlsave(stream);
  1544. X
  1545. X    /* get the stream and format string */
  1546. X    stream = xlgetarg();
  1547. X    if (stream == NIL)
  1548. X    val = stream = newustream();
  1549. X    else {
  1550. X    if (stream == true)
  1551. X        stream = getvalue(s_stdout);
  1552. X    else if (!streamp(stream) && !ustreamp(stream))
  1553. X        xlbadtype(stream);
  1554. X    val = NIL;
  1555. X    }
  1556. X    fmtstring = xlgastring();
  1557. X    fmt = getstring(fmtstring);
  1558. X
  1559. X    /* process the format string */
  1560. X    while (ch = *fmt++)
  1561. X    if (ch == '~') {
  1562. X        switch (*fmt++) {
  1563. X        case '\0':
  1564. X        xlerror("expecting a format directive",cvstring(fmt-1));
  1565. X        case 'a': case 'A':
  1566. X        xlprint(stream,xlgetarg(),FALSE);
  1567. X        break;
  1568. X        case 's': case 'S':
  1569. X        xlprint(stream,xlgetarg(),TRUE);
  1570. X        break;
  1571. X        case '%':
  1572. X        xlterpri(stream);
  1573. X        break;
  1574. X        case '~':
  1575. X        xlputc(stream,'~');
  1576. X        break;
  1577. X        case '\n':
  1578. X        while (*fmt && *fmt != '\n' && isspace(*fmt))
  1579. X            ++fmt;
  1580. X        break;
  1581. X        default:
  1582. X        xlerror("unknown format directive",cvstring(fmt-1));
  1583. X        }
  1584. X    }
  1585. X    else
  1586. X        xlputc(stream,ch);
  1587. X    
  1588. X    /* get the output string for a stream argument of NIL */
  1589. X    if (val) val = getstroutput(val);
  1590. X    xlpopn(2);
  1591. X        
  1592. X    /* return the value */
  1593. X    return (val);
  1594. X}
  1595. X
  1596. X/* getstroutput - get the output stream string (internal) */
  1597. XLOCAL LVAL getstroutput(stream)
  1598. X  LVAL stream;
  1599. X{
  1600. X    unsigned char *str;
  1601. X    LVAL next,val;
  1602. X    int len,ch;
  1603. X
  1604. X    /* compute the length of the stream */
  1605. X    for (len = 0, next = gethead(stream); next != NIL; next = cdr(next))
  1606. X    ++len;
  1607. X
  1608. X    /* create a new string */
  1609. X    val = newstring(len + 1);
  1610. X    
  1611. X    /* copy the characters into the new string */
  1612. X    str = getstring(val);
  1613. X    while ((ch = xlgetc(stream)) != EOF)
  1614. X    *str++ = ch;
  1615. X    *str = '\0';
  1616. X
  1617. X    /* return the string */
  1618. X    return (val);
  1619. X}
  1620. X
  1621. END_OF_FILE
  1622. if test 11944 -ne `wc -c <'src/xlisp/xcore/c/xlfio.c'`; then
  1623.     echo shar: \"'src/xlisp/xcore/c/xlfio.c'\" unpacked with wrong size!
  1624. fi
  1625. # end of 'src/xlisp/xcore/c/xlfio.c'
  1626. fi
  1627. if test -f 'src/xlisp/xcore/c/xlisp.h' -a "${1}" != "-c" ; then 
  1628.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlisp.h'\"
  1629. else
  1630. echo shar: Extracting \"'src/xlisp/xcore/c/xlisp.h'\" \(13662 characters\)
  1631. sed "s/^X//" >'src/xlisp/xcore/c/xlisp.h' <<'END_OF_FILE'
  1632. X/*
  1633. X* -*-C-*-
  1634. X********************************************************************************
  1635. X*
  1636. X* File:         xlisp.h
  1637. X* RCS:          $Header: xlisp.h,v 1.6 89/12/17 19:05:05 mayer Exp $
  1638. X* Description:  libXlisp.a external interfaces
  1639. X* Author:       David Michael Betz; Niels Mayer
  1640. X* Created:      
  1641. X* Modified:     Sun Dec 17 04:50:59 1989 (Niels Mayer) mayer@hplnpm
  1642. X* Language:     C
  1643. X* Package:      N/A
  1644. X* Status:       X11r4 contrib tape release
  1645. X*
  1646. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  1647. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  1648. X*
  1649. X* Permission to use, copy, modify, distribute, and sell this software and its
  1650. X* documentation for any purpose is hereby granted without fee, provided that
  1651. X* the above copyright notice appear in all copies and that both that
  1652. X* copyright notice and this permission notice appear in supporting
  1653. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  1654. X* used in advertising or publicity pertaining to distribution of the software
  1655. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  1656. X* make no representations about the suitability of this software for any
  1657. X* purpose. It is provided "as is" without express or implied warranty.
  1658. X*
  1659. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  1660. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1661. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  1662. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1663. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1664. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1665. X* PERFORMANCE OF THIS SOFTWARE.
  1666. X*
  1667. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  1668. X* 
  1669. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  1670. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  1671. X*
  1672. X********************************************************************************
  1673. X*/
  1674. X
  1675. X#ifndef __XLISP_H__
  1676. X#define __XLISP_H__
  1677. X
  1678. X#include <stdio.h>
  1679. X#include <ctype.h>
  1680. X#include <setjmp.h>
  1681. X
  1682. X/* NNODES    number of nodes to allocate in each request (1000) */
  1683. X/* EDEPTH    evaluation stack depth (2000) */
  1684. X/* ADEPTH    argument stack depth (1000) */
  1685. X/* FORWARD    type of a forward declaration () */
  1686. X/* LOCAL    type of a local function (static) */
  1687. X/* AFMT        printf format for addresses ("%x") */
  1688. X/* FIXTYPE    data type for fixed point numbers (long) */
  1689. X/* ITYPE    fixed point input conversion routine type (long atol()) */
  1690. X/* ICNV        fixed point input conversion routine (atol) */
  1691. X/* IFMT        printf format for fixed point numbers ("%ld") */
  1692. X/* FLOTYPE    data type for floating point numbers (float) */
  1693. X/* OFFTYPE    number the size of an address (int) */
  1694. X
  1695. X
  1696. X/* for BSD & SYSV Unix. */
  1697. X#ifdef UNIX
  1698. X#define NNODES        2000
  1699. X#define AFMT        "%lx"    /* added by NPM */
  1700. X#define OFFTYPE        long    /* added by NPM */
  1701. X#define SAVERESTORE
  1702. X#endif
  1703. X
  1704. X/* for Mips C compiler - Silicon Graphhics */
  1705. X#ifdef _BSD_COMPAT
  1706. X#define LOCAL
  1707. X#endif
  1708. X
  1709. X/* for the Turbo C compiler - MS-DOS, large model */
  1710. X#ifdef _TURBOC_
  1711. X#define NNODES        2000
  1712. X#define AFMT        "%lx"
  1713. X#define OFFTYPE        long
  1714. X#define SAVERESTORE
  1715. X#endif
  1716. X
  1717. X/* for the AZTEC C compiler - MS-DOS, large model */
  1718. X#ifdef AZTEC_LM
  1719. X#define NNODES        2000
  1720. X#define AFMT        "%lx"
  1721. X#define OFFTYPE        long
  1722. X#define CVPTR(x)    ptrtoabs(x)
  1723. X#define NIL        (void *)0
  1724. Xextern long ptrtoabs();
  1725. X#define SAVERESTORE
  1726. X#endif
  1727. X
  1728. X/* for the AZTEC C compiler - Macintosh */
  1729. X#ifdef AZTEC_MAC
  1730. X#define NNODES        2000
  1731. X#define AFMT        "%lx"
  1732. X#define OFFTYPE        long
  1733. X#define NIL        (void *)0
  1734. X#define SAVERESTORE
  1735. X#endif
  1736. X
  1737. X/* for the AZTEC C compiler - Amiga */
  1738. X#ifdef AZTEC_AMIGA
  1739. X#define NNODES        2000
  1740. X#define AFMT        "%lx"
  1741. X#define OFFTYPE        long
  1742. X#define NIL        (void *)0
  1743. X#define SAVERESTORE
  1744. X#endif
  1745. X
  1746. X/* for the Lightspeed C compiler - Macintosh */
  1747. X#ifdef LSC
  1748. X#define NNODES        2000
  1749. X#define AFMT        "%lx"
  1750. X#define OFFTYPE        long
  1751. X#define NIL        (void *)0
  1752. X#define SAVERESTORE
  1753. X#endif
  1754. X
  1755. X/* for the Microsoft C compiler - MS-DOS, large model */
  1756. X#ifdef MSC
  1757. X#define NNODES        2000
  1758. X#define AFMT        "%lx"
  1759. X#define OFFTYPE        long
  1760. X#endif
  1761. X
  1762. X/* for the Mark Williams C compiler - Atari ST */
  1763. X#ifdef MWC
  1764. X#define AFMT        "%lx"
  1765. X#define OFFTYPE        long
  1766. X#endif
  1767. X
  1768. X/* for the Lattice C compiler - Atari ST */
  1769. X#ifdef LATTICE
  1770. X#define FIXTYPE        int
  1771. X#define ITYPE        int atoi()
  1772. X#define ICNV(n)        atoi(n)
  1773. X#define IFMT        "%d"
  1774. X#endif
  1775. X
  1776. X/* for the Digital Research C compiler - Atari ST */
  1777. X#ifdef DR
  1778. X#define LOCAL
  1779. X#define AFMT        "%lx"
  1780. X#define OFFTYPE        long
  1781. X#undef NULL
  1782. X#define NULL        0L
  1783. X#endif
  1784. X
  1785. X
  1786. X/* default important definitions */
  1787. X#ifndef NNODES
  1788. X#define NNODES        1000
  1789. X#endif
  1790. X#ifndef EDEPTH
  1791. X#define EDEPTH        2000
  1792. X#endif
  1793. X#ifndef ADEPTH
  1794. X#define ADEPTH        1000
  1795. X#endif
  1796. X#ifndef FORWARD
  1797. X#define FORWARD
  1798. X#endif
  1799. X#ifndef LOCAL
  1800. X#define LOCAL        static
  1801. X#endif
  1802. X#ifndef AFMT
  1803. X#define AFMT        "%x"
  1804. X#endif
  1805. X#ifndef FIXTYPE
  1806. X#define FIXTYPE        long
  1807. X#endif
  1808. X#ifndef ITYPE
  1809. X#define ITYPE        long atol()
  1810. X#endif
  1811. X#ifndef ICNV
  1812. X#define ICNV(n)        atol(n)
  1813. X#endif
  1814. X#ifndef IFMT
  1815. X#define IFMT        "%ld"
  1816. X#endif
  1817. X#ifndef FLOTYPE
  1818. X#define FLOTYPE        double
  1819. X#endif
  1820. X#ifndef OFFTYPE
  1821. X#define OFFTYPE        int
  1822. X#endif
  1823. X#ifndef CVPTR
  1824. X#define CVPTR(x)    (x)
  1825. X#endif
  1826. X#ifndef UCHAR
  1827. X#define UCHAR        unsigned char
  1828. X#endif
  1829. X
  1830. X/* useful definitions */
  1831. X#ifndef TRUE
  1832. X#define TRUE    (1)
  1833. X#endif
  1834. X#ifndef FALSE
  1835. X#define FALSE    (0)
  1836. X#endif
  1837. X#ifndef NIL
  1838. X#define NIL    (LVAL )0
  1839. X#endif
  1840. X
  1841. X/* instance variable numbers for the class 'Class' */
  1842. X#define MESSAGES    0    /* list   of messages */
  1843. X#define IVARS        1    /* list   of instance variable names */
  1844. X#define CVARS        2    /* list   of class variable names */
  1845. X#define CVALS        3    /* vector of class variable values */
  1846. X#define SUPERCLASS    4    /* pointer to the superclass */
  1847. X#define IVARCNT        5    /* number of class instance variables */
  1848. X#define IVARTOTAL    6    /* total number of instance variables */
  1849. X/* number of instance variables for the class 'Class' */
  1850. X#define CLASSSIZE    7
  1851. X
  1852. X/* Include PROVIDE_XXX #defines for extension modules. *//* JSP */
  1853. X#define MODULE_XLISP_H_PROVIDES
  1854. X#include "../../xmodules.h"
  1855. X#undef MODULE_XLISP_H_PROVIDES
  1856. X
  1857. X/* include the dynamic memory definitions */
  1858. X#include "xldmem.h"
  1859. X
  1860. X/* program limits */
  1861. X#define STRMAX        100        /* maximum length of a string constant */
  1862. X#define HSIZE        199        /* symbol hash table size */
  1863. X#define SAMPLE        100        /* control character sample rate */
  1864. X
  1865. X/* function table offsets for the initialization functions */
  1866. X#define FT_RMHASH    0
  1867. X#define FT_RMQUOTE    1
  1868. X#define FT_RMDQUOTE    2
  1869. X#define FT_RMBQUOTE    3
  1870. X#define FT_RMCOMMA    4
  1871. X#define FT_RMLPAR    5
  1872. X#define FT_RMRPAR    6
  1873. X#define FT_RMSEMI    7
  1874. X/* #define xxxxxx       8 */
  1875. X/* #define yyyyyy       9 */
  1876. X
  1877. X#define FT_CLNEW    10
  1878. X#define FT_CLISNEW    11
  1879. X#define FT_CLANSWER    12
  1880. X#define FT_OBISNEW    13
  1881. X#define FT_OBCLASS    14
  1882. X#define FT_OBSHOW    15
  1883. X
  1884. X#define LAST_FUNTAB_POINTER_USED_BY_libXlisp FT_OBSHOW
  1885. X
  1886. X/* include hybrid function in xlisp symbol table */ /* Voodoo */
  1887. X/* use from within user implemented xlinclude_hybrid_prims */    
  1888. X/* or from within user implemented .h which xmodules.h includes */
  1889. X#define DEFINE_SUBR(a,b)   xldefine_prim(a, SUBR, b);
  1890. X#define DEFINE_FSUBR(a,b)  xldefine_prim(a, FSUBR, b);
  1891. X
  1892. X/* macro to push a value onto the argument stack */
  1893. X#define pusharg(x)    {if (xlsp >= xlargstktop) xlargstkoverflow();\
  1894. X             *xlsp++ = (x);}
  1895. X
  1896. X/* macros to protect pointers */
  1897. X#define xlstkcheck(n)    {if (xlstack - (n) < xlstkbase) xlstkoverflow();}
  1898. X#define xlsave(n)    {*--xlstack = &n; n = NIL;}
  1899. X#define xlprotect(n)    {*--xlstack = &n;}
  1900. X
  1901. X/* check the stack and protect a single pointer */
  1902. X#define xlsave1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  1903. X                         *--xlstack = &n; n = NIL;}
  1904. X#define xlprot1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  1905. X                         *--xlstack = &n;}
  1906. X
  1907. X/* macros to pop pointers off the stack */
  1908. X#define xlpop()        {++xlstack;}
  1909. X#define xlpopn(n)    {xlstack+=(n);}
  1910. X
  1911. X/* macros to manipulate the lexical environment */
  1912. X#define xlframe(e)    cons(NIL,e)
  1913. X#define xlbind(s,v)    xlpbind(s,v,xlenv)
  1914. X#define xlfbind(s,v)    xlpbind(s,v,xlfenv);
  1915. X#define xlpbind(s,v,e)    {rplaca(e,cons(cons(s,v),car(e)));}
  1916. X
  1917. X/* macros to manipulate the dynamic environment */
  1918. X#define xldbind(s,v)    {xldenv = cons(cons(s,getvalue(s)),xldenv);\
  1919. X             setvalue(s,v);}
  1920. X#define xlunbind(e)    {for (; xldenv != (e); xldenv = cdr(xldenv))\
  1921. X               setvalue(car(car(xldenv)),cdr(car(xldenv)));}
  1922. X
  1923. X/* type predicates */                   
  1924. X#define atom(x)        ((x) == NIL || ntype(x) != CONS)
  1925. X#define null(x)        ((x) == NIL)
  1926. X#define listp(x)    ((x) == NIL || ntype(x) == CONS)
  1927. X#define consp(x)    ((x) && ntype(x) == CONS)
  1928. X#define subrp(x)    ((x) && ntype(x) == SUBR)
  1929. X#define fsubrp(x)    ((x) && ntype(x) == FSUBR)
  1930. X#define stringp(x)    ((x) && ntype(x) == STRING)
  1931. X#define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  1932. X#define streamp(x)    ((x) && ntype(x) == STREAM)
  1933. X
  1934. X#define objectp(x)    ((x) && ntype(x) == OBJECT)
  1935. X
  1936. X#define fixp(x)        ((x) && ntype(x) == FIXNUM)
  1937. X#define floatp(x)    ((x) && ntype(x) == FLONUM)
  1938. X#define vectorp(x)    ((x) && ntype(x) == VECTOR)
  1939. X#define closurep(x)    ((x) && ntype(x) == CLOSURE)
  1940. X#define charp(x)    ((x) && ntype(x) == CHAR)
  1941. X#define ustreamp(x)    ((x) && ntype(x) == USTREAM)
  1942. X#define structp(x)    ((x) && ntype(x) == STRUCT)
  1943. X#define boundp(x)    (getvalue(x) != s_unbound)
  1944. X#define fboundp(x)    (getfunction(x) != s_unbound)
  1945. X
  1946. X/* shorthand functions */
  1947. X#define consa(x)    cons(x,NIL)
  1948. X#define consd(x)    cons(NIL,x)
  1949. X
  1950. X/* set element of a vector */ /* Voodoo */
  1951. X#define stuff_fixnum(arg, ind, val) ((arg)->n_vdata[ind])->n_fixnum = (val)
  1952. X#define stuff_flonum(arg, ind, val) ((arg)->n_vdata[ind])->n_flonum = (val)
  1953. X
  1954. X/* argument list parsing macros */
  1955. X#define xlgetarg()    (testarg(nextarg()))
  1956. X#define xllastarg()    {if (xlargc != 0) xltoomany();}
  1957. X#define testarg(e)    (moreargs() ? (e) : xltoofew())
  1958. X#define typearg(tp)    (tp(*xlargv) ? nextarg() : xlbadtype(*xlargv))
  1959. X#define nextarg()    (--xlargc, *xlargv++)
  1960. X#define moreargs()    (xlargc > 0)
  1961. X
  1962. X/* macros to get arguments of a particular type */
  1963. X#define xlgacons()    (testarg(typearg(consp)))
  1964. X#define xlgalist()    (testarg(typearg(listp)))
  1965. X#define xlgasymbol()    (testarg(typearg(symbolp)))
  1966. X#define xlgastring()    (testarg(typearg(stringp)))
  1967. X#define xlgaobject()    (testarg(typearg(objectp)))
  1968. X#define xlgafixnum()    (testarg(typearg(fixp)))
  1969. X#define xlgaflonum()    (testarg(typearg(floatp)))
  1970. X#define xlgachar()    (testarg(typearg(charp)))
  1971. X#define xlgavector()    (testarg(typearg(vectorp)))
  1972. X#define xlgastream()    (testarg(typearg(streamp)))
  1973. X#define xlgaustream()    (testarg(typearg(ustreamp)))
  1974. X#define xlgaclosure()    (testarg(typearg(closurep)))
  1975. X#define xlgastruct()    (testarg(typearg(structp)))
  1976. X
  1977. X#ifndef OPTIMAL        /* Voodoo */
  1978. X#define xlsetjmp(context)         setjmp(context)
  1979. X#define xllongjmp(context, mask)     longjmp(context, mask)
  1980. X#else
  1981. X#define xlsetjmp(context)         0
  1982. X#define xllongjmp(context, mask) \
  1983. X{ \
  1984. X    xlfatal("can't recover, bye..."); \
  1985. X    exit(0); \
  1986. X    }
  1987. X#endif
  1988. X
  1989. X/* function definition structure */
  1990. Xtypedef struct {
  1991. X    char *fd_name;    /* function name */
  1992. X    int fd_type;    /* function type */
  1993. X    LVAL (*fd_subr)();    /* function entry point */
  1994. X} FUNDEF;
  1995. X
  1996. X/* execution context flags */
  1997. X#define CF_GO        0x0001
  1998. X#define CF_RETURN    0x0002
  1999. X#define CF_THROW    0x0004
  2000. X#define CF_ERROR    0x0008
  2001. X#define CF_CLEANUP    0x0010
  2002. X#define CF_CONTINUE    0x0020
  2003. X#define CF_TOPLEVEL    0x0040
  2004. X#define CF_BRKLEVEL    0x0080
  2005. X#define CF_UNWIND    0x0100
  2006. X
  2007. X/* execution context */
  2008. Xtypedef struct context {
  2009. X    int c_flags;            /* context type flags */
  2010. X    LVAL c_expr;            /* expression (type dependant) */
  2011. X    jmp_buf c_jmpbuf;            /* longjmp context */
  2012. X    struct context *c_xlcontext;    /* old value of xlcontext */
  2013. X    LVAL **c_xlstack;            /* old value of xlstack */
  2014. X    LVAL *c_xlargv;            /* old value of xlargv */
  2015. X    int c_xlargc;            /* old value of xlargc */
  2016. X    LVAL *c_xlfp;            /* old value of xlfp */
  2017. X    LVAL *c_xlsp;            /* old value of xlsp */
  2018. X    LVAL c_xlenv;            /* old value of xlenv */
  2019. X    LVAL c_xlfenv;            /* old value of xlfenv */
  2020. X    LVAL c_xldenv;            /* old value of xldenv */
  2021. X} CONTEXT;
  2022. X
  2023. X/* external variables */
  2024. Xextern LVAL **xlstktop;           /* top of the evaluation stack */
  2025. Xextern LVAL **xlstkbase;    /* base of the evaluation stack */
  2026. Xextern LVAL **xlstack;        /* evaluation stack pointer */
  2027. Xextern LVAL *xlargstkbase;    /* base of the argument stack */
  2028. Xextern LVAL *xlargstktop;    /* top of the argument stack */
  2029. Xextern LVAL *xlfp;        /* argument frame pointer */
  2030. Xextern LVAL *xlsp;        /* argument stack pointer */
  2031. Xextern LVAL *xlargv;        /* current argument vector */
  2032. Xextern int xlargc;        /* current argument count */
  2033. X
  2034. X/* external procedure declarations */
  2035. Xextern LVAL xleval();        /* evaluate an expression */
  2036. Xextern LVAL xlapply();        /* apply a function to arguments */
  2037. Xextern LVAL xlsubr();        /* enter a subr/fsubr */
  2038. Xextern LVAL xlenter();        /* enter a symbol */
  2039. Xextern LVAL xlmakesym();    /* make an uninterned symbol */
  2040. Xextern LVAL xlgetvalue();    /* get value of a symbol (checked) */
  2041. Xextern LVAL xlxgetvalue();    /* get value of a symbol */
  2042. Xextern LVAL xlgetfunction();    /* get functional value of a symbol */
  2043. Xextern LVAL xlxgetfunction();    /* get functional value of a symbol (checked) */
  2044. Xextern LVAL xlexpandmacros();    /* expand macros in a form */
  2045. Xextern LVAL xlgetprop();    /* get the value of a property */
  2046. Xextern LVAL xlclose();        /* create a function closure */
  2047. X
  2048. Xextern void xldefine_prim();    /* load xlisp function */ /* Voodoo */
  2049. X
  2050. X/* argument list parsing functions */
  2051. Xextern LVAL xlgetfile();          /* get a file/stream argument */
  2052. Xextern LVAL xlgetfname();    /* get a filename argument */
  2053. X
  2054. X/* error reporting functions (don't *really* return at all) */
  2055. Xextern LVAL xltoofew();        /* report "too few arguments" error */
  2056. Xextern LVAL xlbadtype();    /* report "bad argument type" error */
  2057. X
  2058. X
  2059. X/* Include hybrid-class functions. *//* JSP */
  2060. X/* (Last so you can #undef stuff.) *//* JSP */
  2061. X#define MODULE_XLISP_H_GLOBALS
  2062. X#include "../../xmodules.h"
  2063. X#undef MODULE_XLISP_H_GLOBALS
  2064. X
  2065. X#endif /* __XLISP_H__ */
  2066. END_OF_FILE
  2067. if test 13662 -ne `wc -c <'src/xlisp/xcore/c/xlisp.h'`; then
  2068.     echo shar: \"'src/xlisp/xcore/c/xlisp.h'\" unpacked with wrong size!
  2069. fi
  2070. # end of 'src/xlisp/xcore/c/xlisp.h'
  2071. fi
  2072. if test -f 'src/xlisp/xcore/c/xlmath.c' -a "${1}" != "-c" ; then 
  2073.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlmath.c'\"
  2074. else
  2075. echo shar: Extracting \"'src/xlisp/xcore/c/xlmath.c'\" \(11975 characters\)
  2076. sed "s/^X//" >'src/xlisp/xcore/c/xlmath.c' <<'END_OF_FILE'
  2077. X/* -*-C-*-
  2078. X********************************************************************************
  2079. X*
  2080. X* File:         xlmath.c
  2081. X* RCS:          $Header: xlmath.c,v 1.3 89/11/25 05:40:35 mayer Exp $
  2082. X* Description:  xlisp built-in arithmetic functions
  2083. X* Author:       David Michael Betz
  2084. X* Created:      
  2085. X* Modified:     Sat Nov 25 05:40:27 1989 (Niels Mayer) mayer@hplnpm
  2086. X* Language:     C
  2087. X* Package:      N/A
  2088. X* Status:       X11r4 contrib tape release
  2089. X*
  2090. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2091. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2092. X*
  2093. X* Permission to use, copy, modify, distribute, and sell this software and its
  2094. X* documentation for any purpose is hereby granted without fee, provided that
  2095. X* the above copyright notice appear in all copies and that both that
  2096. X* copyright notice and this permission notice appear in supporting
  2097. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2098. X* used in advertising or publicity pertaining to distribution of the software
  2099. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2100. X* make no representations about the suitability of this software for any
  2101. X* purpose. It is provided "as is" without express or implied warranty.
  2102. X*
  2103. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2104. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2105. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2106. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2107. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2108. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2109. X* PERFORMANCE OF THIS SOFTWARE.
  2110. X*
  2111. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2112. X* 
  2113. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2114. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2115. X*
  2116. X********************************************************************************
  2117. X*/
  2118. Xstatic char rcs_identity[] = "@(#)$Header: xlmath.c,v 1.3 89/11/25 05:40:35 mayer Exp $";
  2119. X
  2120. X
  2121. X#include "xlisp.h"
  2122. X#include <math.h>
  2123. X
  2124. X/* external variables */
  2125. Xextern LVAL true;
  2126. X
  2127. X/* forward declarations */
  2128. XFORWARD LVAL unary();
  2129. XFORWARD LVAL binary();
  2130. XFORWARD LVAL predicate();
  2131. XFORWARD LVAL compare();
  2132. X
  2133. X/* binary functions */
  2134. XLVAL xadd()    { return (binary('+')); } /* + */
  2135. XLVAL xsub()    { return (binary('-')); } /* - */
  2136. XLVAL xmul()    { return (binary('*')); } /* * */
  2137. XLVAL xdiv()    { return (binary('/')); } /* / */
  2138. XLVAL xrem()    { return (binary('%')); } /* rem */
  2139. XLVAL xmin()    { return (binary('m')); } /* min */
  2140. XLVAL xmax()    { return (binary('M')); } /* max */
  2141. XLVAL xexpt()   { return (binary('E')); } /* expt */
  2142. XLVAL xlogand() { return (binary('&')); } /* logand */
  2143. XLVAL xlogior() { return (binary('|')); } /* logior */
  2144. XLVAL xlogxor() { return (binary('^')); } /* logxor */
  2145. X
  2146. X/* xgcd - greatest common divisor */
  2147. XLVAL xgcd()
  2148. X{
  2149. X    FIXTYPE m,n,r;
  2150. X    LVAL arg;
  2151. X
  2152. X    if (!moreargs())            /* check for identity case */
  2153. X    return (cvfixnum((FIXTYPE)0));
  2154. X    arg = xlgafixnum();
  2155. X    n = getfixnum(arg);
  2156. X    if (n < (FIXTYPE)0) n = -n;        /* absolute value */
  2157. X    while (moreargs()) {
  2158. X    arg = xlgafixnum();
  2159. X    m = getfixnum(arg);
  2160. X    if (m < (FIXTYPE)0) m = -m;    /* absolute value */
  2161. X    for (;;) {            /* euclid's algorithm */
  2162. X        r = m % n;
  2163. X        if (r == (FIXTYPE)0)
  2164. X        break;
  2165. X        m = n;
  2166. X        n = r;
  2167. X    }
  2168. X    }
  2169. X    return (cvfixnum(n));
  2170. X}
  2171. X
  2172. X/* binary - handle binary operations */
  2173. XLOCAL LVAL binary(fcn)
  2174. X  int fcn;
  2175. X{
  2176. X    FIXTYPE ival,iarg;
  2177. X    FLOTYPE fval,farg;
  2178. X    LVAL arg;
  2179. X    int mode;
  2180. X
  2181. X    /* get the first argument */
  2182. X    arg = xlgetarg();
  2183. X
  2184. X    /* set the type of the first argument */
  2185. X    if (fixp(arg)) {
  2186. X    ival = getfixnum(arg);
  2187. X    mode = 'I';
  2188. X    }
  2189. X    else if (floatp(arg)) {
  2190. X    fval = getflonum(arg);
  2191. X    mode = 'F';
  2192. X    }
  2193. X    else
  2194. X    xlerror("bad argument type",arg);
  2195. X
  2196. X    /* treat a single argument as a special case */
  2197. X    if (!moreargs()) {
  2198. X    switch (fcn) {
  2199. X    case '-':
  2200. X        switch (mode) {
  2201. X        case 'I':
  2202. X        ival = -ival;
  2203. X        break;
  2204. X        case 'F':
  2205. X        fval = -fval;
  2206. X        break;
  2207. X        }
  2208. X        break;
  2209. X    case '/':
  2210. X        switch (mode) {
  2211. X        case 'I':
  2212. X        checkizero(ival);
  2213. X        ival = 1 / ival;
  2214. X        break;
  2215. X        case 'F':
  2216. X        checkfzero(fval);
  2217. X        fval = 1.0 / fval;
  2218. X        break;
  2219. X        }
  2220. X    }
  2221. X    }
  2222. X
  2223. X    /* handle each remaining argument */
  2224. X    while (moreargs()) {
  2225. X
  2226. X    /* get the next argument */
  2227. X    arg = xlgetarg();
  2228. X
  2229. X    /* check its type */
  2230. X    if (fixp(arg)) {
  2231. X        switch (mode) {
  2232. X        case 'I':
  2233. X            iarg = getfixnum(arg);
  2234. X            break;
  2235. X        case 'F':
  2236. X            farg = (FLOTYPE)getfixnum(arg);
  2237. X        break;
  2238. X        }
  2239. X    }
  2240. X    else if (floatp(arg)) {
  2241. X        switch (mode) {
  2242. X        case 'I':
  2243. X            fval = (FLOTYPE)ival;
  2244. X        farg = getflonum(arg);
  2245. X        mode = 'F';
  2246. X        break;
  2247. X        case 'F':
  2248. X            farg = getflonum(arg);
  2249. X        break;
  2250. X        }
  2251. X    }
  2252. X    else
  2253. X        xlerror("bad argument type",arg);
  2254. X
  2255. X    /* accumulate the result value */
  2256. X    switch (mode) {
  2257. X    case 'I':
  2258. X        switch (fcn) {
  2259. X        case '+':    ival += iarg; break;
  2260. X        case '-':    ival -= iarg; break;
  2261. X        case '*':    ival *= iarg; break;
  2262. X        case '/':    checkizero(iarg); ival /= iarg; break;
  2263. X        case '%':    checkizero(iarg); ival %= iarg; break;
  2264. X        case 'M':    if (iarg > ival) ival = iarg; break;
  2265. X        case 'm':    if (iarg < ival) ival = iarg; break;
  2266. X        case '&':    ival &= iarg; break;
  2267. X        case '|':    ival |= iarg; break;
  2268. X        case '^':    ival ^= iarg; break;
  2269. X        default:    badiop();
  2270. X        }
  2271. X        break;
  2272. X    case 'F':
  2273. X        switch (fcn) {
  2274. X        case '+':    fval += farg; break;
  2275. X        case '-':    fval -= farg; break;
  2276. X        case '*':    fval *= farg; break;
  2277. X        case '/':    checkfzero(farg); fval /= farg; break;
  2278. X        case 'M':    if (farg > fval) fval = farg; break;
  2279. X        case 'm':    if (farg < fval) fval = farg; break;
  2280. X        case 'E':    fval = pow(fval,farg); break;
  2281. X        default:    badfop();
  2282. X        }
  2283. X            break;
  2284. X    }
  2285. X    }
  2286. X
  2287. X    /* return the result */
  2288. X    switch (mode) {
  2289. X    case 'I':    return (cvfixnum(ival));
  2290. X    case 'F':    return (cvflonum(fval));
  2291. X    }
  2292. X}
  2293. X
  2294. X/* checkizero - check for integer division by zero */
  2295. XLOCAL checkizero(iarg)
  2296. X  FIXTYPE iarg;
  2297. X{
  2298. X    if (iarg == 0)
  2299. X    xlfail("division by zero");
  2300. X}
  2301. X
  2302. X/* checkfzero - check for floating point division by zero */
  2303. XLOCAL checkfzero(farg)
  2304. X  FLOTYPE farg;
  2305. X{
  2306. X    if (farg == 0.0)
  2307. X    xlfail("division by zero");
  2308. X}
  2309. X
  2310. X/* checkfneg - check for square root of a negative number */
  2311. XLOCAL checkfneg(farg)
  2312. X  FLOTYPE farg;
  2313. X{
  2314. X    if (farg < 0.0)
  2315. X    xlfail("square root of a negative number");
  2316. X}
  2317. X
  2318. X/* unary functions */
  2319. XLVAL xlognot() { return (unary('~')); } /* lognot */
  2320. XLVAL xabs()    { return (unary('A')); } /* abs */
  2321. XLVAL xadd1()   { return (unary('+')); } /* 1+ */
  2322. XLVAL xsub1()   { return (unary('-')); } /* 1- */
  2323. XLVAL xsin()    { return (unary('S')); } /* sin */
  2324. XLVAL xcos()    { return (unary('C')); } /* cos */
  2325. XLVAL xtan()    { return (unary('T')); } /* tan */
  2326. XLVAL xasin()   { return (unary('s')); } /* asin */
  2327. XLVAL xacos()   { return (unary('c')); } /* acos */
  2328. XLVAL xatan()   { return (unary('t')); } /* atan */
  2329. XLVAL xexp()    { return (unary('E')); } /* exp */
  2330. XLVAL xsqrt()   { return (unary('R')); } /* sqrt */
  2331. XLVAL xfix()    { return (unary('I')); } /* truncate */
  2332. XLVAL xfloat()  { return (unary('F')); } /* float */
  2333. XLVAL xrand()   { return (unary('?')); } /* random */
  2334. X
  2335. X/* unary - handle unary operations */
  2336. XLOCAL LVAL unary(fcn)
  2337. X  int fcn;
  2338. X{
  2339. X    FLOTYPE fval;
  2340. X    FIXTYPE ival;
  2341. X    LVAL arg;
  2342. X
  2343. X    /* get the argument */
  2344. X    arg = xlgetarg();
  2345. X    xllastarg();
  2346. X
  2347. X    /* check its type */
  2348. X    if (fixp(arg)) {
  2349. X    ival = getfixnum(arg);
  2350. X    switch (fcn) {
  2351. X    case '~':    ival = ~ival; break;
  2352. X    case 'A':    ival = (ival < 0 ? -ival : ival); break;
  2353. X    case '+':    ival++; break;
  2354. X    case '-':    ival--; break;
  2355. X    case 'I':    break;
  2356. X    case 'F':    return (cvflonum((FLOTYPE)ival));
  2357. X    case '?':    ival = (FIXTYPE)osrand((int)ival); break;
  2358. X    default:    badiop();
  2359. X    }
  2360. X    return (cvfixnum(ival));
  2361. X    }
  2362. X    else if (floatp(arg)) {
  2363. X    fval = getflonum(arg);
  2364. X    switch (fcn) {
  2365. X    case 'A':    fval = (fval < 0.0 ? -fval : fval); break;
  2366. X    case '+':    fval += 1.0; break;
  2367. X    case '-':    fval -= 1.0; break;
  2368. X    case 'S':    fval = sin(fval); break;
  2369. X    case 'C':    fval = cos(fval); break;
  2370. X    case 'T':    fval = tan(fval); break;
  2371. X    case 's':    fval = asin(fval); break;
  2372. X    case 'c':    fval = acos(fval); break;
  2373. X    case 't':    fval = atan(fval); break;
  2374. X    case 'E':    fval = exp(fval); break;
  2375. X    case 'R':    checkfneg(fval); fval = sqrt(fval); break;
  2376. X    case 'I':    return (cvfixnum((FIXTYPE)fval));
  2377. X    case 'F':    break;
  2378. X    default:    badfop();
  2379. X    }
  2380. X    return (cvflonum(fval));
  2381. X    }
  2382. X    else
  2383. X    xlerror("bad argument type",arg);
  2384. X}
  2385. X
  2386. X/* unary predicates */
  2387. XLVAL xminusp() { return (predicate('-')); } /* minusp */
  2388. XLVAL xzerop()  { return (predicate('Z')); } /* zerop */
  2389. XLVAL xplusp()  { return (predicate('+')); } /* plusp */
  2390. XLVAL xevenp()  { return (predicate('E')); } /* evenp */
  2391. XLVAL xoddp()   { return (predicate('O')); } /* oddp */
  2392. X
  2393. X/* predicate - handle a predicate function */
  2394. XLOCAL LVAL predicate(fcn)
  2395. X  int fcn;
  2396. X{
  2397. X    FLOTYPE fval;
  2398. X    FIXTYPE ival;
  2399. X    LVAL arg;
  2400. X
  2401. X    /* get the argument */
  2402. X    arg = xlgetarg();
  2403. X    xllastarg();
  2404. X
  2405. X    /* check the argument type */
  2406. X    if (fixp(arg)) {
  2407. X    ival = getfixnum(arg);
  2408. X    switch (fcn) {
  2409. X    case '-':    ival = (ival < 0); break;
  2410. X    case 'Z':    ival = (ival == 0); break;
  2411. X    case '+':    ival = (ival > 0); break;
  2412. X    case 'E':    ival = ((ival & 1) == 0); break;
  2413. X    case 'O':    ival = ((ival & 1) != 0); break;
  2414. X    default:    badiop();
  2415. X    }
  2416. X    }
  2417. X    else if (floatp(arg)) {
  2418. X    fval = getflonum(arg);
  2419. X    switch (fcn) {
  2420. X    case '-':    ival = (fval < 0); break;
  2421. X    case 'Z':    ival = (fval == 0); break;
  2422. X    case '+':    ival = (fval > 0); break;
  2423. X    default:    badfop();
  2424. X    }
  2425. X    }
  2426. X    else
  2427. X    xlerror("bad argument type",arg);
  2428. X
  2429. X    /* return the result value */
  2430. X    return (ival ? true : NIL);
  2431. X}
  2432. X
  2433. X/* comparison functions */
  2434. XLVAL xlss() { return (compare('<')); } /* < */
  2435. XLVAL xleq() { return (compare('L')); } /* <= */
  2436. XLVAL xequ() { return (compare('=')); } /* = */
  2437. XLVAL xneq() { return (compare('#')); } /* /= */
  2438. XLVAL xgeq() { return (compare('G')); } /* >= */
  2439. XLVAL xgtr() { return (compare('>')); } /* > */
  2440. X
  2441. X/* compare - common compare function */
  2442. XLOCAL LVAL compare(fcn)
  2443. X  int fcn;
  2444. X{
  2445. X    FIXTYPE icmp,ival,iarg;
  2446. X    FLOTYPE fcmp,fval,farg;
  2447. X    LVAL arg;
  2448. X    int mode;
  2449. X
  2450. X    /* get the first argument */
  2451. X    arg = xlgetarg();
  2452. X
  2453. X    /* set the type of the first argument */
  2454. X    if (fixp(arg)) {
  2455. X    ival = getfixnum(arg);
  2456. X    mode = 'I';
  2457. X    }
  2458. X    else if (floatp(arg)) {
  2459. X    fval = getflonum(arg);
  2460. X    mode = 'F';
  2461. X    }
  2462. X    else
  2463. X    xlerror("bad argument type",arg);
  2464. X
  2465. X    /* handle each remaining argument */
  2466. X    for (icmp = TRUE; icmp && moreargs(); ival = iarg, fval = farg) {
  2467. X
  2468. X    /* get the next argument */
  2469. X    arg = xlgetarg();
  2470. X
  2471. X    /* check its type */
  2472. X    if (fixp(arg)) {
  2473. X        switch (mode) {
  2474. X        case 'I':
  2475. X            iarg = getfixnum(arg);
  2476. X            break;
  2477. X        case 'F':
  2478. X            farg = (FLOTYPE)getfixnum(arg);
  2479. X        break;
  2480. X        }
  2481. X    }
  2482. X    else if (floatp(arg)) {
  2483. X        switch (mode) {
  2484. X        case 'I':
  2485. X            fval = (FLOTYPE)ival;
  2486. X        farg = getflonum(arg);
  2487. X        mode = 'F';
  2488. X        break;
  2489. X        case 'F':
  2490. X            farg = getflonum(arg);
  2491. X        break;
  2492. X        }
  2493. X    }
  2494. X    else
  2495. X        xlerror("bad argument type",arg);
  2496. X
  2497. X    /* compute result of the compare */
  2498. X    switch (mode) {
  2499. X    case 'I':
  2500. X        icmp = ival - iarg;
  2501. X        switch (fcn) {
  2502. X        case '<':    icmp = (icmp < 0); break;
  2503. X        case 'L':    icmp = (icmp <= 0); break;
  2504. X        case '=':    icmp = (icmp == 0); break;
  2505. X        case '#':    icmp = (icmp != 0); break;
  2506. X        case 'G':    icmp = (icmp >= 0); break;
  2507. X        case '>':    icmp = (icmp > 0); break;
  2508. X        }
  2509. X        break;
  2510. X    case 'F':
  2511. X        fcmp = fval - farg;
  2512. X        switch (fcn) {
  2513. X        case '<':    icmp = (fcmp < 0.0); break;
  2514. X        case 'L':    icmp = (fcmp <= 0.0); break;
  2515. X        case '=':    icmp = (fcmp == 0.0); break;
  2516. X        case '#':    icmp = (fcmp != 0.0); break;
  2517. X        case 'G':    icmp = (fcmp >= 0.0); break;
  2518. X        case '>':    icmp = (fcmp > 0.0); break;
  2519. X        }
  2520. X        break;
  2521. X    }
  2522. X    }
  2523. X
  2524. X    /* return the result */
  2525. X    return (icmp ? true : NIL);
  2526. X}
  2527. X
  2528. X/* badiop - bad integer operation */
  2529. XLOCAL badiop()
  2530. X{
  2531. X    xlfail("bad integer operation");
  2532. X}
  2533. X
  2534. X/* badfop - bad floating point operation */
  2535. XLOCAL badfop()
  2536. X{
  2537. X    xlfail("bad floating point operation");
  2538. X}
  2539. END_OF_FILE
  2540. if test 11975 -ne `wc -c <'src/xlisp/xcore/c/xlmath.c'`; then
  2541.     echo shar: \"'src/xlisp/xcore/c/xlmath.c'\" unpacked with wrong size!
  2542. fi
  2543. # end of 'src/xlisp/xcore/c/xlmath.c'
  2544. fi
  2545. if test -f 'src/xlisp/xcore/c/xlstruct.c' -a "${1}" != "-c" ; then 
  2546.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlstruct.c'\"
  2547. else
  2548. echo shar: Extracting \"'src/xlisp/xcore/c/xlstruct.c'\" \(12885 characters\)
  2549. sed "s/^X//" >'src/xlisp/xcore/c/xlstruct.c' <<'END_OF_FILE'
  2550. X/* -*-C-*-
  2551. X********************************************************************************
  2552. X*
  2553. X* File:         xlstruct.c
  2554. X* RCS:          $Header: xlstruct.c,v 1.2 89/11/25 05:47:24 mayer Exp $
  2555. X* Description:  the defstruct facility
  2556. X* Author:       David Michael Betz
  2557. X* Created:      
  2558. X* Modified:     Sat Nov 25 05:47:17 1989 (Niels Mayer) mayer@hplnpm
  2559. X* Language:     C
  2560. X* Package:      N/A
  2561. X* Status:       X11r4 contrib tape release
  2562. X*
  2563. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2564. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2565. X*
  2566. X* Permission to use, copy, modify, distribute, and sell this software and its
  2567. X* documentation for any purpose is hereby granted without fee, provided that
  2568. X* the above copyright notice appear in all copies and that both that
  2569. X* copyright notice and this permission notice appear in supporting
  2570. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2571. X* used in advertising or publicity pertaining to distribution of the software
  2572. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2573. X* make no representations about the suitability of this software for any
  2574. X* purpose. It is provided "as is" without express or implied warranty.
  2575. X*
  2576. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2577. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2578. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2579. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2580. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2581. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2582. X* PERFORMANCE OF THIS SOFTWARE.
  2583. X*
  2584. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2585. X* 
  2586. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2587. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2588. X*
  2589. X********************************************************************************
  2590. X*/
  2591. Xstatic char rcs_identity[] = "@(#)$Header: xlstruct.c,v 1.2 89/11/25 05:47:24 mayer Exp $";
  2592. X
  2593. X
  2594. X#include "xlisp.h"
  2595. X
  2596. X/* external variables */
  2597. Xextern LVAL xlenv,xlfenv;
  2598. Xextern LVAL s_lambda,s_quote,lk_key,true;
  2599. Xextern char buf[];
  2600. X
  2601. X/* local variables */
  2602. Xstatic prefix[STRMAX+1];
  2603. X
  2604. X/* xmkstruct - the '%make-struct' function */
  2605. XLVAL xmkstruct()
  2606. X{
  2607. X    LVAL type,val;
  2608. X    int i;
  2609. X
  2610. X    /* get the structure type */
  2611. X    type = xlgasymbol();
  2612. X
  2613. X    /* make the structure */
  2614. X    val = newstruct(type,xlargc);
  2615. X
  2616. X    /* store each argument */
  2617. X    for (i = 1; moreargs(); ++i)
  2618. X    setelement(val,i,nextarg());
  2619. X    xllastarg();
  2620. X
  2621. X    /* return the structure */
  2622. X    return (val);
  2623. X}
  2624. X
  2625. X/* xcpystruct - the '%copy-struct' function */
  2626. XLVAL xcpystruct()
  2627. X{
  2628. X    LVAL str,val;
  2629. X    int size,i;
  2630. X    str = xlgastruct();
  2631. X    xllastarg();
  2632. X    size = getsz(str);
  2633. X    val = newstruct(getelement(str,0),size-1);
  2634. X    for (i = 1; i < size; ++i)
  2635. X    setelement(val,i,getelement(str,i));
  2636. X    return (val);
  2637. X}
  2638. X
  2639. X/* xstrref - the '%struct-ref' function */
  2640. XLVAL xstrref()
  2641. X{
  2642. X    LVAL str,val;
  2643. X    int i;
  2644. X    str = xlgastruct();
  2645. X    val = xlgafixnum(); i = (int)getfixnum(val);
  2646. X    xllastarg();
  2647. X    return (getelement(str,i));
  2648. X}
  2649. X
  2650. X/* xstrset - the '%struct-set' function */
  2651. XLVAL xstrset()
  2652. X{
  2653. X    LVAL str,val;
  2654. X    int i;
  2655. X    str = xlgastruct();
  2656. X    val = xlgafixnum(); i = (int)getfixnum(val);
  2657. X    val = xlgetarg();
  2658. X    xllastarg();
  2659. X    setelement(str,i,val);
  2660. X    return (val);
  2661. X}
  2662. X
  2663. X/* xstrtypep - the '%struct-type-p' function */
  2664. XLVAL xstrtypep()
  2665. X{
  2666. X    LVAL type,val;
  2667. X    type = xlgasymbol();
  2668. X    val = xlgetarg();
  2669. X    xllastarg();
  2670. X    return (structp(val) && getelement(val,0) == type ? true : NIL);
  2671. X}
  2672. X
  2673. X/* xdefstruct - the 'defstruct' special form */
  2674. XLVAL xdefstruct()
  2675. X{
  2676. X    LVAL structname,slotname,defexpr,sym,tmp,args,body;
  2677. X    LVAL options,oargs,slots;
  2678. X    char *pname;
  2679. X    int slotn;
  2680. X    
  2681. X    /* protect some pointers */
  2682. X    xlstkcheck(6);
  2683. X    xlsave(structname);
  2684. X    xlsave(slotname);
  2685. X    xlsave(defexpr);
  2686. X    xlsave(args);
  2687. X    xlsave(body);
  2688. X    xlsave(tmp);
  2689. X    
  2690. X    /* initialize */
  2691. X    args = body = NIL;
  2692. X    slotn = 0;
  2693. X
  2694. X    /* get the structure name */
  2695. X    tmp = xlgetarg();
  2696. X    if (symbolp(tmp)) {
  2697. X    structname = tmp;
  2698. X    strcpy(prefix,getstring(getpname(structname)));
  2699. X    strcat(prefix,"-");
  2700. X    }
  2701. X
  2702. X    /* get the structure name and options */
  2703. X    else if (consp(tmp) && symbolp(car(tmp))) {
  2704. X    structname = car(tmp);
  2705. X    strcpy(prefix,getstring(getpname(structname)));
  2706. X    strcat(prefix,"-");
  2707. X
  2708. X    /* handle the list of options */
  2709. X    for (options = cdr(tmp); consp(options); options = cdr(options)) {
  2710. X
  2711. X        /* get the next argument */
  2712. X        tmp = car(options);
  2713. X        
  2714. X        /* handle options that don't take arguments */
  2715. X        if (symbolp(tmp)) {
  2716. X        pname = (char *) getstring(getpname(tmp));
  2717. X        xlerror("unknown option",tmp);
  2718. X        }
  2719. X
  2720. X        /* handle options that take arguments */
  2721. X        else if (consp(tmp) && symbolp(car(tmp))) {
  2722. X        pname = (char *) getstring(getpname(car(tmp)));
  2723. X        oargs = cdr(tmp);
  2724. X
  2725. X        /* check for the :CONC-NAME keyword */
  2726. X        if (strcmp(pname,":CONC-NAME") == 0) {
  2727. X
  2728. X            /* get the name of the structure to include */
  2729. X            if (!consp(oargs) || !symbolp(car(oargs)))
  2730. X            xlerror("expecting a symbol",oargs);
  2731. X
  2732. X            /* save the prefix */
  2733. X            strcpy(prefix,getstring(getpname(car(oargs))));
  2734. X        }
  2735. X
  2736. X        /* check for the :INCLUDE keyword */
  2737. X        else if (strcmp(pname,":INCLUDE") == 0) {
  2738. X
  2739. X            /* get the name of the structure to include */
  2740. X            if (!consp(oargs) || !symbolp(car(oargs)))
  2741. X            xlerror("expecting a structure name",oargs);
  2742. X            tmp = car(oargs);
  2743. X            oargs = cdr(oargs);
  2744. X
  2745. X            /* add each slot from the included structure */
  2746. X            slots = xlgetprop(tmp,xlenter("*STRUCT-SLOTS*"));
  2747. X            for (; consp(slots); slots = cdr(slots)) {
  2748. X            if (consp(car(slots)) && consp(cdr(car(slots)))) {
  2749. X
  2750. X                /* get the next slot description */
  2751. X                tmp = car(slots);
  2752. X
  2753. X                /* create the slot access functions */
  2754. X                addslot(car(tmp),car(cdr(tmp)),++slotn,&args,&body);
  2755. X            }
  2756. X            }
  2757. X
  2758. X            /* handle slot initialization overrides */
  2759. X            for (; consp(oargs); oargs = cdr(oargs)) {
  2760. X            tmp = car(oargs);
  2761. X            if (symbolp(tmp)) {
  2762. X                slotname = tmp;
  2763. X                defexpr = NIL;
  2764. X            }
  2765. X            else if (consp(tmp) && symbolp(car(tmp))) {
  2766. X                slotname = car(tmp);
  2767. X                defexpr = (consp(cdr(tmp)) ? car(cdr(tmp)) : NIL);
  2768. X            }
  2769. X            else
  2770. X                xlerror("bad slot description",tmp);
  2771. X            updateslot(args,slotname,defexpr);
  2772. X            }
  2773. X        }
  2774. X        else
  2775. X            xlerror("unknown option",tmp);
  2776. X        }
  2777. X        else
  2778. X        xlerror("bad option syntax",tmp);
  2779. X    }
  2780. X    }
  2781. X
  2782. X    /* get each of the structure members */
  2783. X    while (moreargs()) {
  2784. X    
  2785. X    /* get the slot name and default value expression */
  2786. X    tmp = xlgetarg();
  2787. X    if (symbolp(tmp)) {
  2788. X        slotname = tmp;
  2789. X        defexpr = NIL;
  2790. X    }
  2791. X    else if (consp(tmp) && symbolp(car(tmp))) {
  2792. X        slotname = car(tmp);
  2793. X        defexpr = (consp(cdr(tmp)) ? car(cdr(tmp)) : NIL);
  2794. X    }
  2795. X    else
  2796. X        xlerror("bad slot description",tmp);
  2797. X    
  2798. X    /* create a closure for non-trival default expressions */
  2799. X    if (defexpr != NIL) {
  2800. X        tmp = newclosure(NIL,s_lambda,xlenv,xlfenv);
  2801. X        setbody(tmp,cons(defexpr,NIL));
  2802. X        tmp = cons(tmp,NIL);
  2803. X        defexpr = tmp;
  2804. X    }
  2805. X
  2806. X    /* create the slot access functions */
  2807. X    addslot(slotname,defexpr,++slotn,&args,&body);
  2808. X    }
  2809. X    
  2810. X    /* store the slotnames and default expressions */
  2811. X    xlputprop(structname,args,xlenter("*STRUCT-SLOTS*"));
  2812. X
  2813. X    /* enter the MAKE-xxx symbol */
  2814. X    sprintf(buf,"MAKE-%s",getstring(getpname(structname)));
  2815. X    sym = xlenter(buf);
  2816. X
  2817. X    /* make the MAKE-xxx function */
  2818. X    args = cons(lk_key,args);
  2819. X    tmp = cons(structname,NIL);
  2820. X    tmp = cons(s_quote,tmp);
  2821. X    body = cons(tmp,body);
  2822. X    body = cons(xlenter("%MAKE-STRUCT"),body);
  2823. X    body = cons(body,NIL);
  2824. X    setfunction(sym,
  2825. X        xlclose(sym,s_lambda,args,body,xlenv,xlfenv));
  2826. X
  2827. X    /* enter the xxx-P symbol */
  2828. X    sprintf(buf,"%s-P",getstring(getpname(structname)));
  2829. X    sym = xlenter(buf);
  2830. X
  2831. X    /* make the xxx-P function */
  2832. X    args = cons(xlenter("X"),NIL);
  2833. X    body = cons(xlenter("X"),NIL);
  2834. X    tmp = cons(structname,NIL);
  2835. X    tmp = cons(s_quote,tmp);
  2836. X    body = cons(tmp,body);
  2837. X    body = cons(xlenter("%STRUCT-TYPE-P"),body);
  2838. X    body = cons(body,NIL);
  2839. X    setfunction(sym,
  2840. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2841. X
  2842. X    /* enter the COPY-xxx symbol */
  2843. X    sprintf(buf,"COPY-%s",getstring(getpname(structname)));
  2844. X    sym = xlenter(buf);
  2845. X
  2846. X    /* make the COPY-xxx function */
  2847. X    args = cons(xlenter("X"),NIL);
  2848. X    body = cons(xlenter("X"),NIL);
  2849. X    body = cons(xlenter("%COPY-STRUCT"),body);
  2850. X    body = cons(body,NIL);
  2851. X    setfunction(sym,
  2852. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2853. X
  2854. X    /* restore the stack */
  2855. X    xlpopn(6);
  2856. X
  2857. X    /* return the structure name */
  2858. X    return (structname);
  2859. X}
  2860. X
  2861. X/* xlrdstruct - convert a list to a structure (used by the reader) */
  2862. XLVAL xlrdstruct(list)
  2863. X  LVAL list;
  2864. X{
  2865. X    LVAL structname,sym,slotname,expr,last,val;
  2866. X
  2867. X    /* protect the new structure */
  2868. X    xlsave1(expr);
  2869. X
  2870. X    /* get the structure name */
  2871. X    if (!consp(list) || !symbolp(car(list)))
  2872. X    xlerror("bad structure initialization list",list);
  2873. X    structname = car(list);
  2874. X    list = cdr(list);
  2875. X
  2876. X    /* enter the MAKE-xxx symbol */
  2877. X    sprintf(buf,"MAKE-%s",getstring(getpname(structname)));
  2878. X
  2879. X    /* initialize the MAKE-xxx function call expression */
  2880. X    expr = cons(xlenter(buf),NIL);
  2881. X    last = expr;
  2882. X
  2883. X    /* turn the rest of the initialization list into keyword arguments */
  2884. X    while (consp(list) && consp(cdr(list))) {
  2885. X
  2886. X    /* get the slot keyword name */
  2887. X    slotname = car(list);
  2888. X    if (!symbolp(slotname))
  2889. X        xlerror("expecting a slot name",slotname);
  2890. X    sprintf(buf,":%s",getstring(getpname(slotname)));
  2891. X
  2892. X    /* add the slot keyword */
  2893. X    rplacd(last,cons(xlenter(buf),NIL));
  2894. X    last = cdr(last);
  2895. X    list = cdr(list);
  2896. X
  2897. X    /* add the value expression */
  2898. X    rplacd(last,cons(car(list),NIL));
  2899. X    last = cdr(last);
  2900. X    list = cdr(list);
  2901. X    }
  2902. X
  2903. X    /* make sure all of the initializers were used */
  2904. X    if (consp(list))
  2905. X    xlerror("bad structure initialization list",list);
  2906. X
  2907. X    /* invoke the creation function */
  2908. X    val = xleval(expr);
  2909. X
  2910. X    /* restore the stack */
  2911. X    xlpop();
  2912. X
  2913. X    /* return the new structure */
  2914. X    return (val);
  2915. X}
  2916. X
  2917. X/* xlprstruct - print a structure (used by printer) */
  2918. Xxlprstruct(fptr,vptr,flag)
  2919. X  LVAL fptr,vptr; int flag;
  2920. X{
  2921. X    LVAL next;
  2922. X    int i,n;
  2923. X    xlputc(fptr,'#'); xlputc(fptr,'S'); xlputc(fptr,'(');
  2924. X    xlprint(fptr,getelement(vptr,0),flag);
  2925. X    next = xlgetprop(getelement(vptr,0),xlenter("*STRUCT-SLOTS*"));
  2926. X    for (i = 1, n = getsz(vptr) - 1; i <= n && consp(next); ++i) {
  2927. X    if (consp(car(next))) { /* should always succeed */
  2928. X        xlputc(fptr,' ');
  2929. X        xlprint(fptr,car(car(next)),flag);
  2930. X        xlputc(fptr,' ');
  2931. X        xlprint(fptr,getelement(vptr,i),flag);
  2932. X    }
  2933. X    next = cdr(next);
  2934. X    }
  2935. X    xlputc(fptr,')');
  2936. X}
  2937. X
  2938. X/* addslot - make the slot access functions */
  2939. XLOCAL addslot(slotname,defexpr,slotn,pargs,pbody)
  2940. X  LVAL slotname,defexpr; int slotn; LVAL *pargs,*pbody;
  2941. X{
  2942. X    LVAL sym,args,body,tmp;
  2943. X    
  2944. X    /* protect some pointers */
  2945. X    xlstkcheck(4);
  2946. X    xlsave(sym);
  2947. X    xlsave(args);
  2948. X    xlsave(body);
  2949. X    xlsave(tmp);
  2950. X    
  2951. X    /* construct the update function name */
  2952. X    sprintf(buf,"%s%s",prefix,getstring(getpname(slotname)));
  2953. X    sym = xlenter(buf);
  2954. X    
  2955. X    /* make the access function */
  2956. X    args = cons(xlenter("S"),NIL);
  2957. X    body = cons(cvfixnum((FIXTYPE)slotn),NIL);
  2958. X    body = cons(xlenter("S"),body);
  2959. X    body = cons(xlenter("%STRUCT-REF"),body);
  2960. X    body = cons(body,NIL);
  2961. X    setfunction(sym,
  2962. X        xlclose(sym,s_lambda,args,body,NIL,NIL));
  2963. X
  2964. X    /* make the update function */
  2965. X    args = cons(xlenter("V"),NIL);
  2966. X    args = cons(xlenter("S"),args);
  2967. X    body = cons(xlenter("V"),NIL);
  2968. X    body = cons(cvfixnum((FIXTYPE)slotn),body);
  2969. X    body = cons(xlenter("S"),body);
  2970. X    body = cons(xlenter("%STRUCT-SET"),body);
  2971. X    body = cons(body,NIL);
  2972. X    xlputprop(sym,
  2973. X          xlclose(NIL,s_lambda,args,body,NIL,NIL),
  2974. X          xlenter("*SETF*"));
  2975. X
  2976. X    /* add the slotname to the make-xxx keyword list */
  2977. X    tmp = cons(defexpr,NIL);
  2978. X    tmp = cons(slotname,tmp);
  2979. X    tmp = cons(tmp,NIL);
  2980. X    if ((args = *pargs) == NIL)
  2981. X    *pargs = tmp;
  2982. X    else {
  2983. X    while (cdr(args) != NIL)
  2984. X        args = cdr(args);
  2985. X    rplacd(args,tmp);
  2986. X    }
  2987. X    
  2988. X    /* add the slotname to the %make-xxx argument list */
  2989. X    tmp = cons(slotname,NIL);
  2990. X    if ((body = *pbody) == NIL)
  2991. X    *pbody = tmp;
  2992. X    else {
  2993. X    while (cdr(body) != NIL)
  2994. X        body = cdr(body);
  2995. X    rplacd(body,tmp);
  2996. X    }
  2997. X
  2998. X    /* restore the stack */
  2999. X    xlpopn(4);
  3000. X}
  3001. X
  3002. X/* updateslot - update a slot definition */
  3003. XLOCAL updateslot(args,slotname,defexpr)
  3004. X  LVAL args,slotname,defexpr;
  3005. X{
  3006. X    LVAL tmp;
  3007. X    for (; consp(args); args = cdr(args))
  3008. X    if (slotname == car(car(args))) {
  3009. X        if (defexpr != NIL) {
  3010. X        xlsave1(tmp);
  3011. X        tmp = newclosure(NIL,s_lambda,xlenv,xlfenv);
  3012. X        setbody(tmp,cons(defexpr,NIL));
  3013. X        tmp = cons(tmp,NIL);
  3014. X        defexpr = tmp;
  3015. X        xlpop();
  3016. X        }
  3017. X        rplaca(cdr(car(args)),defexpr);
  3018. X        break;
  3019. X    }
  3020. X    if (args == NIL)
  3021. X    xlerror("unknown slot name",slotname);
  3022. X}
  3023. END_OF_FILE
  3024. if test 12885 -ne `wc -c <'src/xlisp/xcore/c/xlstruct.c'`; then
  3025.     echo shar: \"'src/xlisp/xcore/c/xlstruct.c'\" unpacked with wrong size!
  3026. fi
  3027. # end of 'src/xlisp/xcore/c/xlstruct.c'
  3028. fi
  3029. echo shar: End of archive 6 \(of 16\).
  3030. cp /dev/null ark6isdone
  3031. MISSING=""
  3032. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  3033.     if test ! -f ark${I}isdone ; then
  3034.     MISSING="${MISSING} ${I}"
  3035.     fi
  3036. done
  3037. if test "${MISSING}" = "" ; then
  3038.     echo You have unpacked all 16 archives.
  3039.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3040. else
  3041.     echo You still need to unpack the following archives:
  3042.     echo "        " ${MISSING}
  3043. fi
  3044. ##  End of shell archive.
  3045. exit 0
  3046.